View Full Version : maintaining a SELECT value in the SELECT tag??

15 Aug 2005, 10:22 AM

I have a <select> defined in a form.

My question is , how do I maintain the value of the select after my button has been pressed.

if was a input field, the value would be maintained using value='request.form(select)' but htis is not possible witha select.



16 Aug 2005, 03:44 AM
You mean to retain the state of the control if the form is reloaded? If so you have to set "selected" against the relevant option in the select e.g.

<option value="1">x</option>
<option value="2" selected>y</option>
<option value="3">z</option>

How bets to do this depends on your programming language and the source of the data for the select options. Ideally you will be able to loop through the options and then the code to test if the current option is selected can be written just once. e.g. (pseudocode)

if({value} = {formvalue})
selected = " selected"
selected = ""
end if
output(<option value="{value}"{selected}>{text}</option>);
end while