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
populating drop down menus
Moderator: General Moderators
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:
<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>
";
?>- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
You could also take a loot to this code snippet: viewtopic.php?t=14029