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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron C

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

    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="StartMont h" onchange="locat ion.href =
    'thispage.cfm?S tartMonth=_____ __'">

    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

    #2
    Re: Dynamically setting query string with &lt;select&g t; 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="StartMont h" onchange="locat ion.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.c fm" and the method is "get",
    then all you need for the onchange handler is "this.form.subm it()".
    Normal form handling will set the query string for you.

    Comment

    • RobB

      #3
      Re: Dynamically setting query string with &lt;select&g t; onclick() handler

      Aaron C <agchandler@com cast.net> wrote in message news:<mrWdnbnm1 9qZeAbcRVn-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="StartMont h" onchange="locat ion.href =
      > 'thispage.cfm?S tartMonth=_____ __'">
      >
      > 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="StartMont h"
      onchange="if(v= options[selectedIndex].value)top.loca tion='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.

      Comment

      Working...