I am developing a small web site. I have a login Page (login_form.php) from where user has to select there user type from dropdown box values are "Administrator", "Store Keeper", "User". When user select "User" option from list in onchange event I am opening one popup window (depart.php) from which they have to select their "Department" all department are fetched from database(MySql). Now which ever Department is slected by user that should be displayed on the Parent window beside the Drop Down Box

Please can I any one help me.

Making variables available across different modules like this is best done using session variables.

I am developing a small web site. I have a login Page (login_form.php) from where user has to select there user type from dropdown box values are "Administrator", "Store Keeper", "User". When user select "User" option from list in onchange event I am opening one popup window (depart.php) from which they have to select their "Department" all department are fetched from database(MySql). Now which ever Department is slected by user that should be displayed on the Parent window beside the Drop Down Box

Please can I any one help me.

But you are opening this new window using javascript and not submitting the form on first page .
Post your new window page's code here

This is the code of child window

<html>
<head>
<title>
      Department
</title>
<script type="text/javascript">
function closer()
{
this.close();
}
</script>
</head>
<body>
Select Department
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("navy") or die(mysql_error()); 

$query = "SELECT * FROM depatment"; 
$result = mysql_query($query); 

echo "<select>";
while($row = mysql_fetch_array($result))
{ 
echo "<option>$row[Dept_Name]</option>";
}
echo "</select>";
?>
  <input type="submit" name="Submit" onClick="closer()" value="Submit">
</body></html>

This is the code of child window

<html>
<head>
<title>
      Department
</title>
<script type="text/javascript">
function closer()
{
this.close();
}
</script>
</head>
<body>
Select Department
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("navy") or die(mysql_error()); 

$query = "SELECT * FROM depatment"; 
$result = mysql_query($query); 

echo "<select>";
while($row = mysql_fetch_array($result))
{ 
echo "<option>$row[Dept_Name]</option>";
}
echo "</select>";
?>
  <input type="submit" name="Submit" onClick="closer()" value="Submit">
</body></html>

You need to modify the code a little bit to get it working that way -

<script type="text/javascript">
function closer()
{
window.opener.focus();
this.close();
}
function sel()
{
var selIndex = document.getElementById('someid').selectedIndex;
var str = document.getElementById('someid').options[selIndex].value; 
window.opener.document.getElementById('ParentWindoTextBoxIDHere').innerHTML = str;
}
</script>

</head>
<body>
Select Department
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("navy") or die(mysql_error()); 

$query = "SELECT * FROM depatment"; 
$result = mysql_query($query); 
echo "<select id='someid'>";
while($row = mysql_fetch_array($result))
{ 
echo "<option>$row[Dept_Name]</option>";
}
echo "</select>";
?>

Thank you for the code but what to with function sel()....
Where to use it or where to call it?
Please guide me

This is your for reference what I am doing with Parent window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function newwindow()
{
      preview = window.open("dept_wind.php",'popUpWindow','height=100,width=300,left=10,top=10');
}
</script>
</head>
<body>
<p>&nbsp;</p>
<form id="loginForm" name="loginForm" method="post" action="userchek.php">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr>
  <td colspan="3"><strong>DEPARTMET 
    &nbsp;</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="box" onchange="newwindow()">
    <option>Administrator</option>
    <option>Store Keeper</option>
    <option>User</option>
  </select>
    </td>
  </tr>
    <tr>
      <td width="111"><b>Login</b></td>
      <td colspan="2"><input name="login" type="text" class="textfield" id="login" /></td>
    </tr>
    <tr>
      <td><b>Password</b></td>
      <td colspan="2"><br />
        <input name="password" type="password" class="textfield" id="password" />
      <br /></td>
    </tr>
    <tr>
      <td><input type="submit" name="Submit" onclick="newwindow();" value="     LOGIN     " /></td>
      <td width="97"><input type="submit" name="Submit2" value="Forgot Password" /></td>
      <td width="80"><input type="submit" name="Submit3" value="New User" /></td>
    </tr>
  </table>
</form>
</body>
</html>

Thank you for the code but what to with function sel()....
Where to use it or where to call it?
Please guide me

on change of the select element.

This is what you will do with the parent window , I added the div beside the select list element to show the user selection made on the child window.
Put this div's id in the sel() function at the place of id in the line below -

window.opener.document.getElementById('ParentWindoTextBoxIDHere').innerHTML = str;

I can't get you

Please make me understand

This is what you will do with the parent window , I added the div beside the select list element to show the user selection made on the child window.
Put this div's id in the sel() function at the place of id in the line below -

I am not expert like you Boss please hold my fingure... to show the path

Please make me understand


I am not expert like you Boss please hold my fingure... to show the path

Here is the improved code for the parent window -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function newwindow()
{
      preview = window.open("dept_wind.php",'popUpWindow','height=100,width=300,left=10,top=10');
}
</script>
</head>
<body>
<p>&nbsp;</p>
<form id="loginForm" name="loginForm" method="post" action="userchek.php">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr>
  <td colspan="3"><strong>DEPARTMET 
    &nbsp;</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="box" onchange="newwindow()">
    <option>Administrator</option>
    <option>Store Keeper</option>
    <option>User</option>
  </select>
  <div id="showSel" ></div>
    </td>
  </tr>
    <tr>
      <td width="111"><b>Login</b></td>
      <td colspan="2"><input name="login" type="text" class="textfield" id="login" /></td>
    </tr>
    <tr>
      <td><b>Password</b></td>
      <td colspan="2"><br />
        <input name="password" type="password" class="textfield" id="password" />
      <br /></td>
    </tr>
    <tr>
      <td><input type="submit" name="Submit" onclick="newwindow();" value="     LOGIN     " /></td>
      <td width="97"><input type="submit" name="Submit2" value="Forgot Password" /></td>
      <td width="80"><input type="submit" name="Submit3" value="New User" /></td>
    </tr>
  </table>
</form>
</body>
</html>

this can be the child window -

<script type="text/javascript">
function closer()
{
window.opener.focus();
this.close();
}
function sel()
{
var selIndex = document.getElementById('someid').selectedIndex;
var str = document.getElementById('someid').options[selIndex].value; 
window.opener.document.getElementById('showSel').innerHTML = str;
}
</script>

</head>
<body>
Select Department
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("navy") or die(mysql_error()); 

$query = "SELECT * FROM depatment"; 
$result = mysql_query($query); 
echo "<select id='someid'>";
while($row = mysql_fetch_array($result))
{ 
echo "<option>$row[Dept_Name]</option>";
}
echo "</select>";
?>

Note that inside the sel() function I used the id of the div from the parent window.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.