Page 1 of 1

Remembering input from dynamic drop down lists

Posted: Mon Dec 19, 2005 10:21 am
by stylus
Hello,

I am trying to figure out how to make my form remember what was selected from a drop box when a user submits it but has to go back and correct their inputs.

Here is the code that I am using that needs to be remebered.

Code: Select all

<select name=location_name OnChange=document.workorderform.submit()><option> </option>";
while($row = mssql_fetch_array($results)) {
echo '<option value="'.$row[CustomerID].'">'.$row[CustomerName].'</option>'; 
}
echo "</select>";

Here is some code for some "static" drop boxs I am using, it works good because the optional values are always the same. but in the dynamic list it is choosing any number of options from a list of over 2200 customer names.

Code: Select all

<?php echo '<select name="performed_by">'; 
echo "<option value='Service'"; if($performed_by == 'Service') echo " selected"; echo ">Service</option>";
echo "<option value='Operations'"; if($performed_by == 'Operations') echo " selected"; echo ">Operations</option>";
echo "<option value='Copier Administative'"; if($performed_by == 'Copier Administrative') echo " selected"; echo ">Copier Administrative</option>";
echo "<option value='Furniture Administrative'"; if($performed_by == 'Furniture Administrative') echo " selected"; echo ">Funiture Administative</option>";  
echo "</select>"; 
?>

Posted: Mon Dec 19, 2005 10:30 am
by Burrito
how are your users "going back" to the form page? With the "back" button I presume...if so, there's not much you can do if their browsers dont' remember what the selected option was.

if you're posting back to the page, you can do this:

Code: Select all

echo "<select name=\"location_name\" OnChange=\"document.workorderform.submit()\"><option> </option>"; 
while($row = mssql_fetch_array($results)) { 
echo "<option value=\"".$row[CustomerID]."\" ".(isset($_POST['location_name']) && $_POST['location_name'] == $row['CustomerName'] ? "selected=\"selected\"" : "").">".$row['CustomerName']."</option>"; 
} 
echo "</select>";

Posted: Mon Dec 19, 2005 10:40 am
by stylus
Thanks for the help, it works like you said. My form post back to itself for all the error checking, then once the user confirms everything the data is posted to an action page.

Posted: Mon Dec 19, 2005 10:43 am
by Burrito
in that case, what I posted should work for you...