View Full Version : maintaining a SELECT value in the SELECT tag??
numbenator
15 Aug 2005, 10:22 AM
Hi
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.
cheers.
Steve
DaiWelsh
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.
<select>
<option value="1">x</option>
<option value="2" selected>y</option>
<option value="3">z</option>
</select>
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)
while(getoption)
if({value} = {formvalue})
selected = " selected"
else
selected = ""
end if
output(<option value="{value}"{selected}>{text}</option>);
end while
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.