Connecting Tech Pros Worldwide Forums | Help | Site Map

Dynamically setting query string with <select> onclick() handler

Aaron C
Guest
 
Posts: n/a
#1: Jul 23 '05
This is kindof a newbie question, so please bear with me...

I need to pass the selected option of a <select> tag into a query
string, so that the page is reloaded with the selected option already
chosen. This will occur with the onclick() event hander, and the query
string will be processed using a server-side technology. I'm just not
sure how to word the "onclick" handler. Here's what I have:

<select id="StartMonth" name="StartMonth" onchange="location.href =
'thispage.cfm?StartMonth=_______'">

What is the correct wording to set the underlined portion to whatever
was selected? I know it has to be done with JavaScript, since the
decision is made on the client-side. Any help would be soooo appreciated.

Thanks,
Aaron

Lee
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Dynamically setting query string with <select> onclick() handler


Aaron C said:[color=blue]
>
>This is kindof a newbie question, so please bear with me...
>
>I need to pass the selected option of a <select> tag into a query
>string, so that the page is reloaded with the selected option already
>chosen. This will occur with the onclick() event hander, and the query
>string will be processed using a server-side technology. I'm just not
>sure how to word the "onclick" handler. Here's what I have:
>
><select id="StartMonth" name="StartMonth" onchange="location.href =
>'thispage.cfm?StartMonth=_______'">
>
>What is the correct wording to set the underlined portion to whatever
>was selected? I know it has to be done with JavaScript, since the
>decision is made on the client-side. Any help would be soooo appreciated.[/color]

If the action of your form is "thispage.cfm" and the method is "get",
then all you need for the onchange handler is "this.form.submit()".
Normal form handling will set the query string for you.

RobB
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Dynamically setting query string with <select> onclick() handler


Aaron C <agchandler@comcast.net> wrote in message news:<mrWdnbnm19qZeAbcRVn-sA@comcast.com>...[color=blue]
> This is kindof a newbie question, so please bear with me...
>
> I need to pass the selected option of a <select> tag into a query
> string, so that the page is reloaded with the selected option already
> chosen. This will occur with the onclick() event hander, and the query
> string will be processed using a server-side technology. I'm just not
> sure how to word the "onclick" handler. Here's what I have:
>
> <select id="StartMonth" name="StartMonth" onchange="location.href =
> 'thispage.cfm?StartMonth=_______'">
>
> What is the correct wording to set the underlined portion to whatever
> was selected? I know it has to be done with JavaScript, since the
> decision is made on the client-side. Any help would be soooo appreciated.
>
> Thanks,
> Aaron[/color]

Well - you apparently worded the "onclick" handler - by renaming it
"onchange". Good start. :D

<select id="StartMonth" name="StartMonth"
onchange="if(v=options[selectedIndex].value)top.location='thispage.cfm?StartMonth='+v">

Nothing will happen if the user selects a 'dummy' option (with no
value - typically the top one). Are you sure you want to do this
without an intermediate step, like a button press? UI convention
generally frowns on 'no-mistake' selects.
Closed Thread