PDA

View Full Version : How to keep selected values in select



bumbar
Apr 6th, 2007, 02:04 PM
Hallo!

I want to keep selected values in select list when i click on another
option

<FORM name="f1" action="" method="post">
<SELECT size="1" name="s1">
<OPTION value="val1">val 1</OPTION>
<OPTION value="val2">val 2</OPTION>
<OPTION value="val3">val 3</OPTION>
</SELECT>
<INPUT type="submit" value="Send">
</FORM>

<script>
val = f1.s1.value;
document.write (val);
</script>

When I select option and click "Send", browser going to refresh and option value always equal "val 1".

I want to keep selected values. If I select "val 2", when click "Send", form keep "val 2" values ....

glenngv
Apr 6th, 2007, 09:20 PM
What server-side language are you using? Whatever it is, you can retrieve the selected item in the server-side and then compare it with each option and put the attribute selected="selected" inside the option tag that matches the selected item. For example, when val 2 is selected, the generated HTML after the form is submitted would be:

<SELECT size="1" name="s1">
<OPTION value="val1">val 1</OPTION>
<OPTION value="val2" selected="selected">val 2</OPTION>
<OPTION value="val3">val 3</OPTION>
</SELECT>