tags:

views:

12

answers:

2

Hello everyone

I have a form, that includes a drop down list, and a submit button.

The drop down list has 5 values.

Let's say the user chooses value #3, then clicks submit. How would I prevent the drop down list from setting itself back to value #1?

Thanks!

+2  A: 

use your serverside script to set selected="selected" for the selected <option>.

oezi
I need the selected to be dynamic though. What happens if the user select item #4? If I set selected="selected" for item #3, then when the user clicks the submit button, instead of staying on #4(last item selected) it'll now go to #3.
Idealflip
use you script to set selected for the last selected option... i don't understand whats the problem.
oezi
+1  A: 

After your Submit your side should know what was submitted. You can tell your DropDownList what was seleced befor by setting the seleced Value as selected.

Example:

<select name='myselect'>
<option value='1' <?php if($myselect == '1') { echo 'selected'; } ?>>#1</option>
<option value='2' <?php if($myselect == '2') { echo 'selected'; } ?>>#2</option>
<option value='3' <?php if($myselect == '3') { echo 'selected'; } ?>>#3</option>
</select>
ph3x_m0nk3y