...

View Full Version : How do you have the radio button selected determine next page loaded?



meeka007
01-10-2004, 10:19 PM
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

Oakendin
01-10-2004, 11:58 PM
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/showthread.php?s=&threadid=23153&highlight=radio+submit

meeka007
01-12-2004, 04:11 PM
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.

warhammerdude20
01-12-2004, 09:43 PM
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

glenngv
01-13-2004, 03:13 AM
Your radios have different names making both of them selectable at the same time.

This is the simplest and easiest solution:



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

meeka007
01-13-2004, 03:04 PM
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

toymachine22122
01-13-2004, 04:23 PM
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.

glenngv
01-14-2004, 02:35 AM
There are several ways for javascript to pass data from one page to another. Look at this (http://www.webxpertz.net/faqs/jsfaq/passvars.php).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum