I've integrated a double drop down list into my website and it works great. The problem is the drop down is not the first feature on the form and if you start filling everything out first then change the drop down the form reloads and everything you've already filled out disapears.
Is there a way to have the drop downs load dynamically and not have the entire page refresh?
I'm coding in PHP and using sql to grab my information.
Here's what the code looks like:
echo "<select name='dept' onChange=\"reload(this.form)\" size='1'>";
echo "<option selected value='first'> </option>";
while($noticia2 = mysql_fetch_array($deptresult))
{
if($noticia2['Department']==$dept)
{
echo "<option selected value='$noticia2[Department]'>$noticia2 [Department]</option>"."<BR>";
}
else{
echo "<option value='$noticia2[Department]'>$noticia2
[Department]</option>";
}
}
echo "</select>";
echo "</br>";
if(isset($dept) and strlen($dept) > 0)
{
$query1 = "Select Name from employee where Department = '$dept'";
$salesresult = runQuery($query1);
}
echo "<select name=\"salesmanname\" size=\"1\">";
echo "<option value=\"null\">Not applicable</option>";
$num = mysql_num_fields($salesresult);
while($row = mysql_fetch_array($salesresult))
{
for($i=0;$i<$num;$i++)
echo '<option value="' .$row[$i]. '">'. $row[$i]. '</option>';
}
echo "</select>";
and this is the java script function that is in my header:
function reload(form)
{
var val=form.dept.options[form.dept.options.selectedIndex].value;
self.location='form.php?dept=' + val ;
}
Thanks for your help in advance!!