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 to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    2 Radio buttons and Submit

    Hello,
    I'm currently trying to figure out how I can make each radio button call a different page. For example If i click on radio button 1 and click submit it will take me to www.website1.com and if I click radio button 2 and click submit it will take me to www.website2.com. I would really appreciate your help

    Thank you
    Eric

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,084
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb Something to consider ...

    You don't really need javascript to solve this problem.
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    
    </head>
    <body>
    
    <label>
    <input type="radio" name="RBtn"
     onclick="window.location.href='http://www.webdeveloper.com'">RBtn 1
    </label>
    
    <label>
    <input type="radio" name="RBtn"
     onclick="window.location.href='http://www.codingforums.com'">RBtn 2
    </label>
    
    </body>
    </html>
    Major problem with this type of direction is that you cannot change your mind
    after clicking on the radio button, unlike a checkbox with a separate "GO!" button.

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    You don't really need javascript to solve this problem.
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    
    </head>
    <body>
    
    <label>
    <input type="radio" name="RBtn"
     onclick="window.location.href='http://www.webdeveloper.com'">RBtn 1
    </label>
    
    <label>
    <input type="radio" name="RBtn"
     onclick="window.location.href='http://www.codingforums.com'">RBtn 2
    </label>
    
    </body>
    </html>
    Major problem with this type of direction is that you cannot change your mind
    after clicking on the radio button, unlike a checkbox with a separate "GO!" button.
    Thank you Jmrker!!!
    I've just changed my radio button to checkbox but how would I get the submit button to work after I have selected my checkbox 1 or checkbox 2. I really really appreciate your help.

    Eric-newbie

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,084
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by gogetim_3 View Post
    Thank you Jmrker!!!
    I've just changed my radio button to checkbox but how would I get the submit button to work after I have selected my checkbox 1 or checkbox 2. I really really appreciate your help.

    Eric-newbie
    Problem is solvable but with one piece of missing information...
    Where should the button direct the user to if both checkboxes are checked?
    1st checkbox or 2nd?

    This time a bit of JS is needed.
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    
    function goto() {
      var links = [ 'http://www.webdeveloper.com','http://www.codingforums.com'];
      var flag = -1
      if (document.getElementById('cbox1').checked) { flag = 0; }
      if (document.getElementById('cbox2').checked) { flag = 1; }
      if (flag == -1) { alert('Nothing checked');
                      } else { window.location.href = links[flag]; }
    }
    </script>
    
    </head>
    <body>
    
    <label><input type="checkbox" id="cbox1"> CBox 1 </label>
    <label><input type="checkbox" id="cbox2"> CBox 2 </label>
    <br><button onclick="goto()">Go!</button>
    
    </body>
    </html>
    Last edited by jmrker; 07-15-2011 at 03:23 AM.

  • #5
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok here we go... The check boxes are for 2 different price points. You would only be able to click one check box.

    If Check box 1(www.pricepoint1.com) would be checked and the end user clicks submit it would take them to a check out with 1 dollar checkout.

    If the end user clicks on the second check box the price option would be $2 and when they click submit it will send them to www.pricepoint2.com

    I hope I didnt make this too confusing with my wording.

    Eric

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,084
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by gogetim_3 View Post
    Ok here we go... The check boxes are for 2 different price points. You would only be able to click one check box.
    ...
    Eric
    Checkboxes are not the same as radio buttons.
    It is possible for the user to check both, unlike the radio button which only allows one to be checked.

    If the order is not correct in the earlier post I sent, just alter the logic test.

    Good Luck!

  • #7
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That code the you last posted did it for me. Thank you again jmrker I have a lot to learn and your help is really appreciated.

    Eric

  • #8
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,084
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Thumbs up

    Quote Originally Posted by gogetim_3 View Post
    That code the you last posted did it for me. Thank you again jmrker I have a lot to learn and your help is really appreciated.

    Eric
    You're most welcome.
    Happy to help.


  •  

    Posting Permissions

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