Results 1 to 3 of 3

Thread: Seeking form script that loads targeted pages on submit

  1. #1
    Join Date
    Feb 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Seeking form script that loads targeted pages on submit

    Hi, all!

    I've been searching all morning for a form script that does the following:

    1. User selects options in a form via radio buttons then presses 'submit'.

    2. If radio buttons A & B are selected, page1.html loads on submit.

    3. Alternatively, if radio buttons C & D are selected, page2.html loads on submit.


    Does anyone know where to find such a script? I would prefer to use PHP but for my specific needs it has to be plain ol' Javascript, if possible.

    Cheers

    UC

  2. #2
    Join Date
    Feb 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Apparently radio buttons don't have a selectedIndex or value property so thats annoying but its easy enough to get around by just looping through all the radio buttons in the collection.

    Try this:

    <script>
    function goto(r)
    {
    for (i=0; i<r.length; i++)
    if (r[i].checked) window.location = r[i].value;
    }
    </script>
    <form onsubmit="goto(this.r);return false;">
    <input type=radio name=r value="http://google.com">
    <input type=radio name=r value="http://yahoo.com">
    <input type="submit" value="">
    </form>

  3. #3
    Join Date
    Feb 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That'll work! Thank you very much!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •