...

View Full Version : Need help with option selected - Select Tag



web2007
07-08-2007, 05:23 AM
I am using a select tag on my page and the problem I am having is that when the page is submitted I can determine which option is selected, but the page reloads with the original option selected before the change was made. I tried storing the value in a hidden field and within the for loop used to create the options, I used an if..then..clause but that didn't work. However when I "hard code" the value into the hidden field variable it works correctly.

nbcrockett
07-08-2007, 07:03 AM
Here's an example, but there are other ways to do this that might be simpler depending on your code. If you want to post the code I'll take a look at it.


<select name="Dropdown" size="1" tabindex="23">
<option selected value="One">One</option>
<%
Select Case Request.Form("Dropdown")
Case "Two"
%>
<option selected value="Two">Two</option>
<option value="Three">Three</option>
<option value="Four">Four</option>
<%
Case "Three"
%>
<option value="Two">Two</option>
<option selected value="Three">Three</option>
<option value="Four">Four</option>
<%
Case "Four"
%>
<option value="Two">Two</option>
<option value="Three">Three</option>
<option selected value="Four">Four</option>
<%
Case Else
%>
<option value="Two">Two</option>
<option value="Three">Three</option>
<option value="Four">Four</option>
<%
End Select
%>
</select>

nbcrockett
07-08-2007, 07:04 AM
Here's an example, but there are other ways to do this that might be simpler depending on your code. If you want to post the code I'll take a look at it.


<select name="Dropdown" size="1" tabindex="23">
<option selected value="One">One</option>
<%
Select Case Request.Form("Dropdown")
Case "Two"
%>
<option selected value="Two">Two</option>
<option value="Three">Three</option>
<option value="Four">Four</option>
<%
Case "Three"
%>
<option value="Two">Two</option>
<option selected value="Three">Three</option>
<option value="Four">Four</option>
<%
Case "Four"
%>
<option value="Two">Two</option>
<option value="Three">Three</option>
<option selected value="Four">Four</option>
<%
Case Else
%>
<option value="Two">Two</option>
<option value="Three">Three</option>
<option value="Four">Four</option>
<%
End Select
%>
</select>

web2007
07-08-2007, 02:01 PM
Attached is the code of what I am trying to do.


<html>
<head><title>Test</title></head>
<%
If Request.ServerVariables("HTTP_METHOD") = "POST" THEN
extendedStay = Request.Form("extendedStay")
wsExtendedStay = extendedStay

'For testing purposes only.
response.write "wsExtendedStay is = "&wsExtendedStay&""
End If
%>
<body>
<form name='htlStay' method='post' action='extStay.asp'>
<%
response.write "<select name='extendedStay' size='1'>"
For i=1 to 60
If i=wsExtendedStay Then
response.write "<option value="&i&" selected>"&i&"</option>"
Else
response.write "<option value="&i&">"&i&"</option>"
End If
next
response.write "</select><br /><br />"
response.write "<button type='submit' name='submitForm'>Submit</button>"
%>
</form>
</body>
</html>

nbcrockett
07-08-2007, 10:09 PM
Change this line:


If i=wsExtendedStay Then


To this:


If i = Int(wsExtendedStay) Then

web2007
07-09-2007, 03:55 PM
Thanks so much it worked.

nbcrockett
07-09-2007, 04:18 PM
No problem!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum