PDA

View Full Version : Remember selected combo value after submit?


Dodger
11-09-2002, 07:25 PM
How can I do this?

I'm sure I can use some combination of jscript and asp, but I'm tired and can't think straight...lol

TIA.

whammy
11-09-2002, 09:13 PM
<select name="myselect">
<option value="1"<% If myselect = "1" Then Response.Write(" selected=""selected""") %>>1</option>
<option value="2"<% If myselect = "2" Then Response.Write(" selected=""selected""") %>>1</option>
</select>

Dodger
11-09-2002, 09:43 PM
Perhaps I didn't explain it very well...

Example:

I have a menu: Values 1, 2 and 3.

I select value 2 from the list and 'onchange' the form is submitted and submits the data to the same page.

When the page is returned, what can I do to have option 2 still selected?

TIA.

whammy
11-09-2002, 11:07 PM
<%
myselect = Request.Form("myselect")
%>
<form id="form1" action="thispage.asp" method="post">
<select name="myselect" onchange="this.form.submit()">
<option value="1"<% If myselect = "1" Then Response.Write(" selected=""selected""") %>>1</option>
<option value="2"<% If myselect = "2" Then Response.Write(" selected=""selected""") %>>2</option>
<option value="3"<% If myselect = "3" Then Response.Write(" selected=""selected""") %>>3</option>
</select>
<input type="submit" value="Submit" />
</form>

Dodger
11-10-2002, 09:33 AM
Thanks whammy!! :thumbsup:

whammy
11-10-2002, 10:45 AM
You're welcome. :)

Lpcnew
07-28-2011, 06:39 PM
I've been searching the net and only found this solution here. Only you could say the best way.

Then I'll put on my blog! : D

Big hug.

Old Pedant
07-28-2011, 10:30 PM
If your <select> has more than two or three <option>s, there are better ways.