Click to See Complete Forum and Search --> : no logic
I am struggling to get to grips with this....
I have x number of radiobutton groups - say 3 in each group
question 1 is it ans a, b, or c? answer e.g. a is correct
question 2 ......................answer e.g. c is correct etc....
I want to display some feedback to each question once all questions have been answered.
Can anyone help? Some extra JS comments would also be useful...
crh3675
06-29-2004, 10:49 AM
<script type="text/javascript">
function showAnswer(){
var f=document.forms[0];
var wrong=true;
for(i=0;i<f.q1.length;i++){
if(f["q1_a"].value==f.q1[i].value){
wrong=false;
break;
}else{
wrong=true;
}
}
if(wrong==false){
alert("You got the answer right!")
}else{
alert("Wrong Answer!");
}
}
</script>
<form>
<input type="radio" name="q1" value="a"> Answer A<br/>
<input type="radio" name="q1" value="b"> Answer B<br/>
<input type="radio" name="q1" value="c"> Answer C<br/>
<input type="hidden" name="q1_a" value="a"/>
<input type="button" onclick="showAnswer()" value="Check"/>
</form>
Bhanu
06-29-2004, 11:06 AM
you can modify this as per your requirement
Bhanu
==========================================
<html>
<head>
<title>Bhanu</title>
<script language="JavaScript">
function check(){
for(a=1;a<5;a++){
for(i=0;i<3;i++){
x = "q" + a;
if(document.all[x][i].checked == true){alert(document.all['q1'][i].value);}
}
}
}
</script>
</head>
<body>
<form action="" name="test" onsubmit="return check();">
Q1: xxxxxxxxxxx?<br>
<input type="Radio" name="q1" value="a">A<br>
<input type="Radio" name="q1" value="b">B<br>
<input type="Radio" name="q1" value="c">C<br>
Q2: xxxxxxxxxxx?<br>
<input type="Radio" name="q2" value="a">A<br>
<input type="Radio" name="q2" value="b">B<br>
<input type="Radio" name="q2" value="c">C<br>
Q3: xxxxxxxxxxx?<br>
<input type="Radio" name="q3" value="a">A<br>
<input type="Radio" name="q3" value="b">B<br>
<input type="Radio" name="q3" value="c">C<br>
Q4: xxxxxxxxxxx?<br>
<input type="Radio" name="q4" value="a">A<br>
<input type="Radio" name="q4" value="b">B<br>
<input type="Radio" name="q4" value="c">C<br>
<input type="Submit" value="Submit">
</form>
</body>
</html>
==========================================