Forum Moderators: coopster
// first combo box
<select name="queryTypeCombo" onchange=submitForm()>
<option>-- Please select --</option>
<option value = 1>OnLoan</option>
<option value = 2>Availability</option>
<option value = 3>Missing</option>
<option value = 4>Condemned</option>
</select>
i did a document.form.submit() to get the $_POST['queryTypeCombo'] and store it into a session.
after the onchange() is executed in first combo box, second combo box will be displayed. the option values in the second combo box is dependable on the options selected in first combo box.
// onchange function
function submitForm()
{
document.searchMenuForm.submit();
}
// second combo box
<select name="queryAssetTypeCombo" onchange=submitForm()>
<option>-- Please select --</option>
<option value = Laptop>Laptop</option>
<option value = Olympus Digital Recorder>Olympus Digital Recorder</option>
</select>
my problem is after i have selected the option e.g. OnLoan or Laptop in either the 1st or 2nd combo box, -- Please select -- will always be displayed instead of OnLoan or Laptop in the combo boxes. may i know what has gone wrong? is it because i did a submitForm() that causes the combo boxes to refresh back to -- Please select --? another problem is the options in the second combo box is empty after i have selected Laptop.
how do i display the selected option correctly in the combo boxes?
function retrieveQueryType() {
$query = "select * from ims_status";
$result = mysql_query($query);
echo "<select name=\"queryTypeCombo\" onchange=submitForm()>\n";
echo "<option>-- Please select --</option>\n";
//Now fill the table with data
while ($row = mysql_fetch_array($result))
{
$statusID = $row['statusID'];
$type = $row['type'];
}
}
echo "</select>\n";
}
function retrieveQueryType() {
$query = "select * from ims_status";
$result = mysql_query($query);
echo "<select name=\"queryTypeCombo\" onchange=submitForm()>\n";
echo "<option>-- Please select --</option>\n";
//Now fill the table with data
while ($row = mysql_fetch_array($result))
{
$statusID = $row['statusID'];
$type = $row['type'];
echo "<option value = $statusID>$type</option>\n";
}
//echo "</select>\n";
echo ">$type</option>";
}
I think the problem lies here:
while ($row = mysql_fetch_array($result))
{
$statusID = $row['statusID'];
$type = $row['type'];
echo "<option value = $statusID>$type</option>\n";
}
//echo "</select>\n";
echo ">$type</option>";
}
The final echo, what is that doing exactly? Why have you commented out the closing select? This is possibly the problem. Try the following:
while ($row = mysql_fetch_array($result))
{
echo '<option value="'.$row['statusID'].'">'.$row['type'].'</option>';
}
echo '</select>';}
dc
yup, i have tried the code: echo '<option value="'.$row['statusID'].'">'.$row['type'].'</option>';
result: last item is set as default when page is loaded. i have other combo boxes, the values are dependent on the first combo box. this line of code doesn't seem to work well.