Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need Help with Forms & JavaScript!!

    Hi, here's what I'm hoping someone can help me with:
    I have a form that has a couple radio buttons that people can chose from. What I need is a script that determines which radio button is chosen and then when the user clicks on the "next" button, the site will go on to appropriate html page. So I have 7 radio buttons and 7 subsequent webpages that depending on which radio button is chosen, the user will go to that specific webpage.
    Thanks for any help!

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Houston, TX
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    please use descriptive subjects

    What I would suggest in this case is to put the URL in the value of the radio. Then on submit put that value in a location.href.

    Hope that points you in the right direction,
    Michael

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure what you mean by "put that value in a location.href"??

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="JavaScript">

    function gotoURL(form) {
    var radGrp = form.URL;
    for (var i=0; i<radGrp.length; i++)
    if (radGrp[i].checked) {
    location = radGrp[i].value; return;
    }
    alert('Please choose one of the websites on the list.');
    }

    </script>
    </head>
    <body>
    <form>
    <input name="temp" type="hidden">
    <input name="URL" type="radio" value="javascript&#58;alert('URL 1')"> URL 1<br>
    <input name="URL" type="radio" value="javascript&#58;alert('URL 2')"> URL 2<br>
    <input name="URL" type="radio" value="javascript&#58;alert('URL 3')"> URL 3<br>
    <input name="URL" type="radio" value="javascript&#58;alert('URL 4')"> URL 4<br>
    <input name="URL" type="radio" value="javascript&#58;alert('URL 5')"> URL 5<br>
    <input name="URL" type="radio" value="javascript&#58;alert('URL 6')"> URL 6<br>
    <input name="URL" type="radio" value="javascript&#58;alert('URL 7')"> URL 7<br><br>
    <input type="button" value="Go To Site" onclick="gotoURL(this.form)">
    </form>
    </body>
    </html>

    Just replace the values with real URLs.

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much!


  •  

    Posting Permissions

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