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 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2004
    Location
    Minnesota
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do you have the radio button selected determine next page loaded?

    One my first page I have three pictures with a radio buttom below each. Each of the first three choices have different choices to be made on the next page. So once they select their choice on the first page and hit the select button the page that loads next is based on the radio button selected. How is that accomplished, I've hit a wall trying to figure it out?

    -meeka007

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need a function that runs on submit and detects the value of the radio button and according to that, send the user to the correct URL.

    The below post my help you. You should try the forum search for more options:
    http://www.codingforums.com/showthre...t=radio+submit

  • #3
    New Coder
    Join Date
    Jan 2004
    Location
    Minnesota
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Thanks for the reply. Of course when I searched for the solution I can't find anything, but as soon as I ask the question the answer is right there. Thanks again.

  • #4
    Regular Coder
    Join Date
    Dec 2003
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sulotion

    i hope this helps

    code:

    <html>
    <head>
    <title>blah</title>
    <script language="JavaScript">

    // here is your function

    function findTheChecked(){
    var radio_1 = window.document.form_1.radio_1;
    var radio_2 = window.document.form_1.radio_2;

    // the above locates the checkboxes

    if(radio_1.checked == true){ //this finds which one is checked
    radio_2.checked = false;
    window.location.replace("blah.html"); // change that to the site
    }else{
    if(radio_2.checked == true){
    radio_1.checked = false;
    window.location.replace("blah.html");// change that to the other
    }
    }
    }

    </script>
    </head>
    <body> // these are just the buttons

    <form name="form_1">
    <input type="radio" name="radio_1"
    onClick="findTheChecked();">site 1
    <input type="radio" name="radio_2"
    onClick="findTheChecked();">site 2
    </form>

    </body>
    </html>

    ive already tested it and it works.
    check the comments to find out why this works. and you can just cut and paste it if you want.

    david

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Your radios have different names making both of them selectable at the same time.

    This is the simplest and easiest solution:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function openPic(f){
      for (var i=0;i<f.pic.length;i++){
        if (f.pic[ i ].checked){
          location.href=f.pic[ i ].value;
          break;
        }
      }
    }
    </script>
    </head>
    <body> 
    <form name="myform">
    <input type="radio" name="pic" value="pic1.htm">Picture 1
    <input type="radio" name="pic" value="pic2.htm">Picture 2
    <input type="radio" name="pic" value="pic3.htm">Picture 3
    <p>
    <input type="button" value="Select" onclick="openPic(this.form)">
    </p>
    </form>
    </body>
    </html>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    New Coder
    Join Date
    Jan 2004
    Location
    Minnesota
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks, universal variables?

    Thanks a lot guys, but that brings up another question. How do I save the radio buttons they have selected to a variable so that I can use those previous answers on the last page? I want to take an answer from each page and pull them all up on the last page. Kind of like a quiz but I'm not really building a quiz. I have found some posts dealing with universal variables but I can't get them to work for me. Thanks for helping me out.

    -meeka007
    Last edited by meeka007; 01-13-2004 at 04:06 PM.

  • #7
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Easiest way to do this would probably be to put it all on one page, then add the variables together. As far as I know, JavaScript cannot save or load to external files (like .txt or .ini), which would be the only way to do this. For this type of thing I would suggest a server-side language; CGI would probably be the easiest.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    There are several ways for javascript to pass data from one page to another. Look at this.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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