Stop form dropdown list from refreshing and losing index
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. 开发者_Go百科How would I prevent the drop down list from setting itself back to value #1?
Thanks!
use your serverside script to set selected="selected"
for the selected <option>
.
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>
精彩评论