开发者

Stop form dropdown list from refreshing and losing index

开发者 https://www.devze.com 2022-12-30 18:41 出处:网络
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 dro

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消