...

View Full Version : selecting list boxes



jhogeterp
09-29-2003, 04:02 AM
Hi all. new to php so bear with me here!

I am wondering if there is an easy way for php to automatically reselect an item from a list box.

The purpose is this:
The user will be filling out a form which, before it gets sent to mysql, I want them to double check what they typed in. I am doing this all in one php page. So the user clicks "submit" and it brings them back to the same form asking them to please double check. Everything then is entered in the form already. Witht he text fields I just set the initial value to be it vvalue in the $_POST array. However, I am not quite sure how to do this with the lsit boxes.

Can anyone help? Maybe I am goign about this completely the wrong way?

Spookster
09-29-2003, 04:55 AM
Well to have it re-select what the user chose you would need to check each option like so:



<select name="state">
<option value="none">Select State</option>
<option value="AL" <?php if($_POST['state'] == "AL") echo "selected"; ?>>Alabama</option>
<option value="AK" <?php if($_POST['state'] == "AK") echo "selected"; ?>>Alaska</option>
<option value="AZ" <?php if($_POST['state'] == "AZ") echo "selected"; ?>>Arizona</option>
<option value="AR" <?php if($_POST['state'] == "AR") echo "selected"; ?>>Arkansas</option>
<option value="CA" <?php if($_POST['state'] == "CA") echo "selected"; ?>>California</option>
</select>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum