Form Submission: Final URL that has form options included ??

Discussion in 'Javascript' started by Jared, Jul 9, 2003.

  1. Jared

    Jared Guest

    Hi there
    I am trying to do the following with no luck:

    I want to have a form with two select menus. Each menu will obvisouly
    have different options, each with its own value. Then quite simply,
    when the user clicks on the submit button, I want the resulting URL to
    include options from the select fields ( ie: whatever the user has
    selected.)

    For eg: for a date URL, the final URL might be:

    'http://www.comics.com/' +day+ '/' +month+ '/garfield.gif'

    Hope this makes sense, and appreciate any assistance.
    Thanks,
    Jared
     
    Jared, Jul 9, 2003
    #1
    1. Advertising

  2. Jared

    Daniel Guest

    "Jared" <> wrote in message
    news:...
    > Hi there
    > I am trying to do the following with no luck:
    >
    > I want to have a form with two select menus. Each menu will obvisouly
    > have different options, each with its own value. Then quite simply,
    > when the user clicks on the submit button, I want the resulting URL to
    > include options from the select fields ( ie: whatever the user has
    > selected.)
    >
    > For eg: for a date URL, the final URL might be:
    >
    > 'http://www.comics.com/' +day+ '/' +month+ '/garfield.gif'
    >
    > Hope this makes sense, and appreciate any assistance.
    > Thanks,
    > Jared


    Well, I'm not one hundred what you mean, but maybe this is useful...

    You could create hidden fields to hold the values of the options selected in
    your select boxes, and change their values whenever an option is clicked,
    like this:

    <select name="selectBoxDay" id="selectBoxDay"
    onChange="this.form.day=this.options[this.selectedIndex].value;">
    //options
    </select>
    <select name="selectBoxMonth" id="selectBoxMonth"
    onChange="this.form.month=this.options[this.selectedIndex].value;">
    //options
    </select>

    <input name="day" type="hidden" value="">
    <input name="month" type="hidden" value="">

    - not sure if the onChange syntax is correct, since I haven't checked it ;)

    Would this help?

    Daniel



    --
    There are 10 kinds of people: Those who know binary and those who don't.
     
    Daniel, Jul 9, 2003
    #2
    1. Advertising

  3. Does the url have to be in this format? If not then why don't you just use
    method="get" in the form tag, this will display something like:-

    'http://www.comics.com/nextpage.html?option1=one&option2=two&option3=three'

    Then if you want to pull it out of the querystring on the backend with JS or
    Serverside script it should be easier for you.

    Hope that helps.

    Stu

    "Jared" <> wrote in message
    news:...
    > Hi there
    > I am trying to do the following with no luck:
    >
    > I want to have a form with two select menus. Each menu will obvisouly
    > have different options, each with its own value. Then quite simply,
    > when the user clicks on the submit button, I want the resulting URL to
    > include options from the select fields ( ie: whatever the user has
    > selected.)
    >
    > For eg: for a date URL, the final URL might be:
    >
    > 'http://www.comics.com/' +day+ '/' +month+ '/garfield.gif'
    >
    > Hope this makes sense, and appreciate any assistance.
    > Thanks,
    > Jared
     
    Stuart Palmer, Jul 9, 2003
    #3
  4. This will generate the required URL pattern:

    http://www.comics.com/04/05/page.htm

    This will not submit the form however, so the destination page will not be
    able to read any POST/GET form variables.

    The call to the javascript can be placed in the form tag as an onSubmit
    event, or on a button in the form as an onClick event.

    <script type="text/javascript">
    function ProcessForm(domain,page)
    {
    var formObject=document.forms['myform'];
    var Select1Object=formObject.elements['select1'];
    var Select1Object=formObject.elements['select2'];
    var Select1Value=Select1Object.options[Select1Object.selectedIndex].value;
    var Select2Value=Select2Object.options[Select2Object.selectedIndex].value;

    if(Select1Value=='null')
    {
    return false;
    }

    if(Select2Value=='null')
    {
    return false;
    }

    window.location.href='http://'+domain'/'+Select1Value+'/'+Select2Value+'/'+p
    age;
    }
    </script>

    ....

    <form name="myform" action="#"
    onSubmit="ProcessForm('www.comics.com','page.htm'); return false;">
    <select name="select1">
    <option value="null">Select day</option>
    <option value="01">1</option>
    ....
    <option value="31">31</option>
    </select>
    <select name="select2">
    <option value="null">Select month</option>
    <option value="01">January</option>
    ....
    <option value="12">December</option>
    </select>
    <input type="submit" value="Go">
    <input type="button" value="Go"
    onClick="ProcessForm('www.comics.com','page.htm'); return false;">
    </form>

    "Jared" <> wrote in message
    news:...
    > Hi there
    > I am trying to do the following with no luck:
    >
    > I want to have a form with two select menus. Each menu will obvisouly
    > have different options, each with its own value. Then quite simply,
    > when the user clicks on the submit button, I want the resulting URL to
    > include options from the select fields ( ie: whatever the user has
    > selected.)
    >
    > For eg: for a date URL, the final URL might be:
    >
    > 'http://www.comics.com/' +day+ '/' +month+ '/garfield.gif'


    Do you just want to generate the above URL pattern, or do you want to submit
    the form variables (day, month) as well?

    >
    > Hope this makes sense, and appreciate any assistance.
    > Thanks,
    > Jared
     
    Richard Hockey, Jul 9, 2003
    #4
  5. Jared

    Markus Ernst Guest

    "Jared" <> schrieb im Newsbeitrag
    news:...
    > Hi there
    > I am trying to do the following with no luck:
    >
    > I want to have a form with two select menus. Each menu will obvisouly
    > have different options, each with its own value. Then quite simply,
    > when the user clicks on the submit button, I want the resulting URL to
    > include options from the select fields ( ie: whatever the user has
    > selected.)
    >
    > For eg: for a date URL, the final URL might be:
    >
    > 'http://www.comics.com/' +day+ '/' +month+ '/garfield.gif'
    >
    > Hope this makes sense, and appreciate any assistance.
    > Thanks,
    > Jared


    You could try something like (not tested):

    <form name="myform" action="" method="post"
    onSubmit="document.myform.action='http://www.comics.com/' +
    document.myform.day.value + '/' + document.myform.month.value +
    '/garfield.gif'">

    I am sorry I have no time to figure this out in detail; maybe you have to
    make a onClick on the submit button instead of an onSubmit in the form tag.

    You can also go another way:

    <form name="myform" action="http://www.comics.com/garfield.htm"
    method="get">

    this loads an url with a query string:
    http://www.comics.com/garfield.htm?day=yourday&month=yourmonth

    And you create a document garfield.htm with a script that parses the query
    string and loads the appropriate gif.

    hth
    --
    Markus
     
    Markus Ernst, Jul 9, 2003
    #5
  6. Jared

    Jared Guest

    Thanks all for the help - using the different posts I have com up woth a solution.

    Thanks again !
     
    Jared, Jul 10, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JFCM
    Replies:
    4
    Views:
    5,778
  2. Replies:
    5
    Views:
    542
    Chris Uppal
    Nov 17, 2006
  3. IanR
    Replies:
    2
    Views:
    307
    Albert Hopkins
    Mar 12, 2009
  4. Replies:
    0
    Views:
    246
  5. Replies:
    2
    Views:
    134
    Rick Scott
    Feb 26, 2006
Loading...

Share This Page