473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

highlighting user selected option after form submit

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

Oct 12 '06 #1
7 2398
Did you try basic debugging? Like,

response.write queryMonth

? Did you try making sure you were comparing apples to apples, like

if (clng(i) = clng(queryMonth))

?


<br**********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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

Oct 12 '06 #2

<br**********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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
<select name="eventMonth">
<option value="">-- Month --</option>
<%
dim i
for i = 1 to 12
Response.Write "<option value='" & i & "'"
If i = Cint(queryMonth) Then Response.Write " selected"
Response.Write ">" & MonthName(i) & "</option>" & vbcrlf
next
%>
</select>
--
Mike Brind
Oct 12 '06 #3
wrote on 12 okt 2006 in microsoft.public.inetserver.asp.general:
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>.

Something like this comes from one of my pages:

<select name='theSelection'
style='background-color:#ebddb0;color:#826729;'>
<%
for n=0 to to ubound(optionArray)-1
if request.form("theSelection") = optionArray(n) then
selec = " selected style='color:#c00;background-color:#fbedc0;'"
else
selec = ""
end if
%>
<option value='<%=optionArray(n)%>'<%=selec%>><%=optionArr ay(n)%></option>
<%
next
%>
</select>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 12 '06 #4
i did a CInt on queryMonth, and that worked perfectly. thanks to all.
>Did you try making sure you were comparing apples to apples, like
if (clng(i) = clng(queryMonth))
just one lingering question though...in the code below, since i'm
basically performing the same test, why would this work and not my
actual code? thanks

<%
if (1 = "1") then
response.Write("asdf") //result is this line of code
else
response.Write("rarr")
end if
%>

Oct 12 '06 #5

<br**********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>i did a CInt on queryMonth, and that worked perfectly. thanks to all.
>>Did you try making sure you were comparing apples to apples, like
if (clng(i) = clng(queryMonth))

just one lingering question though...in the code below, since i'm
basically performing the same test, why would this work and not my
actual code? thanks

<%
if (1 = "1") then
response.Write("asdf") //result is this line of code
else
response.Write("rarr")
end if
%>
Because items in the the Request collections are passed as strings. That's
what Aaron meant by comparing apples with apples. You were comparing a
numeric type with a string.

If you ever get stuck on what datatype a variable is, just Response.Write
TypeName(variable).
--
Mike Brind
Oct 12 '06 #6
It's not the same test. You implicitly defined both constants here. In
your original code, you brought in a string from the request collection
(this is NOT implicitly declared) and compared it to something that had been
explicitly cast as a number due to the for loop.


<br**********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>i did a CInt on queryMonth, and that worked perfectly. thanks to all.
>>Did you try making sure you were comparing apples to apples, like
if (clng(i) = clng(queryMonth))

just one lingering question though...in the code below, since i'm
basically performing the same test, why would this work and not my
actual code? thanks

<%
if (1 = "1") then
response.Write("asdf") //result is this line of code
else
response.Write("rarr")
end if
%>

Oct 12 '06 #7
gotcha. thanks aaron

Oct 12 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Nathaniel Maier | last post by:
Hi. How can I send form results to an email address based on what the user selects? e.g. not to the same address all the time, and not to all addresses, but to the one that the user selects. How...
11
by: Shaiboy_UK | last post by:
Hi All, Hope someone can help here!! I'm putting a standard mail page together, that will allow my users to sent templete emails out to people. The files are stored in text files. I have...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
5
by: Raffi | last post by:
Hi folks, I'm new to JavaScript and need some help. I have a form with a select field. Depending on what is selected in this field, I want to display or not display another select field. For...
2
by: iam247 | last post by:
Hi I have an ASP form which only includes an option list. The list is dynamically created but includes a default value, which is an instruction "Select a group". The code is shown at bottom....
1
by: sparksol | last post by:
I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display. I would like to keep the...
4
nomad
by: nomad | last post by:
Hello Everyone: I'm working on a project for a client in which they want to add and delete events for a selected day on a calendar. I have built the calendar and added the events, but I'm having...
17
by: jerrydigital | last post by:
Hello, I have an edit user page that allows the user to view their user information and make changes if possible. I have a simple html login page that directs to an asp page called edituser.asp...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.