Forum Moderators: open

Message Too Old, No Replies

Radio Button Question

         

mackey555

10:34 pm on Aug 8, 2004 (gmt 0)



I'm trying to create a radio button questionaire with five questions and yes or no answers. If the answer is no to any of the questions the user is directed to a sorry page, but if they answer yes to all the questions they are directed to a contact page. I'm newbie and this is probably really easy to do. Thank you ahead of time.

Rambo Tribble

4:44 am on Aug 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getYN(){
var fld_set=document.getElementById("fldSet1"); //grab the fieldset
var rad_flds=fld_set.getElementsByTagName("input"); //get the radio buttons within the fieldset
var rad_cnt=rad_flds.length;
fld_set.onclick=function(){ //onclick event handler on fieldset
var loop_cnt=0;
for(var i=0;i<rad_cnt;i++){ //loop through the radios, abort if a no, continue if 5 yes
if(rad_flds[i].checked)loop_cnt++;
++i;
if(rad_flds[i].checked){
alert("you blew it");
location.reload(true);
}
}
if(loop_cnt==5){
alert("you're home free");
location.reload(true);
}
}
}
</script>
</head>
<body onload="getYN();">
<div>
<form action="">
<fieldset id="fldSet1">
<legend>Survey Questions:</legend>
<label>Question One:
<input type="radio" name="qOne" value="one_y" />yes
<input type="radio" name="qOne" value="one_n" />no
</label><br />
<label>Question Two:
<input type="radio" name="qTwo" value="two_y" />yes
<input type="radio" name="qTwo" value="two_n" />no
</label><br />
<label>Question Three:
<input type="radio" name="qThree" value="three_y" />yes
<input type="radio" name="qThree" value="three_n" />no
</label><br />
<label>Question Four:
<input type="radio" name="qFour" value="four_y" />yes
<input type="radio" name="qFour" value="four_n" />no
</label><br />
<label>Question Five:
<input type="radio" name="qFive" value="five_y" />yes
<input type="radio" name="qFive" value="five_n" />no
</label>
</fieldset>
</form>
</div>
</body>
</html>