I have 5 dependent drop-downs (<select> objects) that after I submit the form to complete the search I want to display the drop-down lists to their previous selections. This works flawlessly in IE but fails to fire in FireFox. To keep the code simple to view since there is lots of it, I'll show you the javascript code that fires on page load. I'm using PHP to build javascript that should be rebuilding the drop-down values and selecting the previous selected value, and when I view source in FireFox after the submission I see all the javascript just like in IE - except it is not repopulating the javascript.
HERE IS THE CODE:
function BodyLoad() {
<?
if (isset($HTTP_POST_VARS["form_sent"])) {
$query = 'SELECT * FROM state';
$Result = mysql_query($query) or die('Query failed: ' . mysql_error());
$ctr = 1;
While( $Row = mysql_fetch_array($Result) ) {
echo "var oState = document.getElementById('myState');\n";
echo "oState.options[$ctr] = new Option('$Row[1]');\n";
echo "oState.options[$ctr].value = '$Row[0]';\n";
//echo "document.frmSearch.select_state.options[$ctr] = new Option('$Row[1]');\n";
//echo "document.frmSearch.select_state.options[$ctr].value = '$Row[0]';\n";
if ($HTTP_POST_VARS["select_state"] == $Row[0]) {
echo "oState.selectedIndex = $ctr;\n";
//echo "document.frmSearch.select_state.selectedIndex = '$ctr';\n";
$StateID = $HTTP_POST_VARS["select_state"];
}
$ctr++;
}
}
END CODE
Note: there are no javascript or PHP errors - so if you see one it is only because I pulled a sub-set of code out ... this is the part not working in FireFox. Also, having the selectedIndex value as a string and as an int doesn't seem to matter. In addition - both methods for setting the selectedIndex (one is commented out) works in IE - neither work in FireFox. I think I tried the DOM1 method and DOM2, but not certain.
Any help is greatly appreciated. Thanks!
Mike
HERE IS THE CODE:
function BodyLoad() {
<?
if (isset($HTTP_POST_VARS["form_sent"])) {
$query = 'SELECT * FROM state';
$Result = mysql_query($query) or die('Query failed: ' . mysql_error());
$ctr = 1;
While( $Row = mysql_fetch_array($Result) ) {
echo "var oState = document.getElementById('myState');\n";
echo "oState.options[$ctr] = new Option('$Row[1]');\n";
echo "oState.options[$ctr].value = '$Row[0]';\n";
//echo "document.frmSearch.select_state.options[$ctr] = new Option('$Row[1]');\n";
//echo "document.frmSearch.select_state.options[$ctr].value = '$Row[0]';\n";
if ($HTTP_POST_VARS["select_state"] == $Row[0]) {
echo "oState.selectedIndex = $ctr;\n";
//echo "document.frmSearch.select_state.selectedIndex = '$ctr';\n";
$StateID = $HTTP_POST_VARS["select_state"];
}
$ctr++;
}
}
END CODE
Note: there are no javascript or PHP errors - so if you see one it is only because I pulled a sub-set of code out ... this is the part not working in FireFox. Also, having the selectedIndex value as a string and as an int doesn't seem to matter. In addition - both methods for setting the selectedIndex (one is commented out) works in IE - neither work in FireFox. I think I tried the DOM1 method and DOM2, but not certain.
Any help is greatly appreciated. Thanks!
Mike