Page 1 of 1

populating drop down menus

Posted: Sat Jan 10, 2004 1:37 pm
by kdehl113
Hello, I have been searching for a while for this question. I have a form which has a couple of drop down menus on it. The form is written in html and is passed to a php script. I want the php script to validate the form and to redisplay info already enetered by the user, only if it fails validation. So what I need to know is how do I get the drop downs to display the data in it's variable back to the drop down?

Kevin

Posted: Sat Jan 10, 2004 3:00 pm
by basdog22
the name or id of the form elements you use are passed as variables to php. So if your drop down is like:

<select name="choice">
<option>var1</option>
<option>var2</option>
<option>var3</option>
</select>

then the variable passed is $choice (will hold the selected: var1, var2 or var3)

so you can do:

Code: Select all

<?php
echo "<select name="choice">
<option selected="selected">$choice</option>
<option>var2</option>
<option>var3</option>
</select>
";

?>

Drop Down

Posted: Sun Jan 11, 2004 3:07 pm
by kdehl113
Thanks, worked great.

Posted: Sun Jan 11, 2004 4:06 pm
by scorphus
You could also take a loot to this code snippet: viewtopic.php?t=14029