...

View Full Version : 2 Radio buttons and Submit



gogetim_3
07-14-2011, 11:40 PM
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

jmrker
07-14-2011, 11:55 PM
You don't really need javascript to solve this problem. :eek:


<!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.

gogetim_3
07-15-2011, 02:26 AM
You don't really need javascript to solve this problem. :eek:


<!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

jmrker
07-15-2011, 03:07 AM
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? :confused:

This time a bit of JS is needed.


<!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>

gogetim_3
07-15-2011, 03:37 AM
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

jmrker
07-15-2011, 03:40 AM
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!
:)

gogetim_3
07-15-2011, 03:42 AM
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

jmrker
07-15-2011, 03:46 AM
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.
:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum