|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
highlighting user selected option after form submitMonth 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 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)) ? <brendan.w***@gmail.com> wrote in message Show quoteHide quote news:1160674161.807700.182900@i42g2000cwa.googlegroups.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 > <brendan.w***@gmail.com> wrote in message
Show quoteHide quote news:1160674161.807700.182900@i42g2000cwa.googlegroups.com... <select name="eventMonth">> 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 > <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 </select>next %> -- Mike Brind 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 Something like this comes from one of my pages:> 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>. > > <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%>><%=optionArray(n)%></option> <% next %> </select> -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) 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 just one lingering question though...in the code below, since i'm>if (clng(i) = clng(queryMonth)) 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 %> <brendan.w***@gmail.com> wrote in message
Show quoteHide quote news:1160676339.764608.260720@h48g2000cwc.googlegroups.com... Because items in the the Request collections are passed as strings. That's >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 > %> > 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 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. <brendan.w***@gmail.com> wrote in message Show quoteHide quote news:1160676339.764608.260720@h48g2000cwc.googlegroups.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 > %> >
Other interesting topics
errors in asp code
Help in writing SQL using request.form.item(i) New session for every page??? Percentage Calculation question.... Carriage Return and Response.Write Output Issue displaying a drop down selection with ASP ADODB.Field error '80020009' Cannot find record Request.BinaryRead(count) wierd Multiple sessions, how to kill only one |
|||||||||||||||||||||||