B
brendan.wong
hello. i have a really simple form that asks the user to select a
Month from a dropdown. the first time a user visits the page, the
highlighted option should be October, which works fine. then, if the
user submits the form, i want the dropdown to highlight whatever
selection that the user made in the resulting page. for example, if
the user chose February, then the code in the resulting page would look
something like <option value="February" selected>.
here's my code:
<%
dim queryMonth
if (Request.querystring("eventMonth") <> "" ) then
queryMonth = Request.querystring("eventMonth")
else
queryMonth = Month(Now())
end if
%>
<form action="events_new.asp" method="get" onSubmit="return
checkRequiredFields(this);">
<select name="eventMonth">
<option value="">-- Month --</option>
<%
dim i
for i = 1 to 12
if (i = queryMonth) then
response.Write("<option value='" & i & "' selected>" & MonthName(i)
& "</option>")
else
response.Write("<option value='" & i & "'>" & MonthName(i) &
"</option>")
end if
next
%>
</select>
<input type="submit" value="Go">
</form>
However, after performing some tests, i'm not getting the effect that i
want. It only works the first time I visit the page. otherwise, if i
submit the form, the "selected" entry in the dropdown is always the
first option <option value="">--Month--</option>. Anyone know what's
going on? Thanks
Month from a dropdown. the first time a user visits the page, the
highlighted option should be October, which works fine. then, if the
user submits the form, i want the dropdown to highlight whatever
selection that the user made in the resulting page. for example, if
the user chose February, then the code in the resulting page would look
something like <option value="February" selected>.
here's my code:
<%
dim queryMonth
if (Request.querystring("eventMonth") <> "" ) then
queryMonth = Request.querystring("eventMonth")
else
queryMonth = Month(Now())
end if
%>
<form action="events_new.asp" method="get" onSubmit="return
checkRequiredFields(this);">
<select name="eventMonth">
<option value="">-- Month --</option>
<%
dim i
for i = 1 to 12
if (i = queryMonth) then
response.Write("<option value='" & i & "' selected>" & MonthName(i)
& "</option>")
else
response.Write("<option value='" & i & "'>" & MonthName(i) &
"</option>")
end if
next
%>
</select>
<input type="submit" value="Go">
</form>
However, after performing some tests, i'm not getting the effect that i
want. It only works the first time I visit the page. otherwise, if i
submit the form, the "selected" entry in the dropdown is always the
first option <option value="">--Month--</option>. Anyone know what's
going on? Thanks