Click to See Complete Forum and Search --> : ashers
ashers
04-17-2003, 03:36 AM
Radio Buttons
Im setting up a quiz where the user clicks in radio buttons to select answers. Heres what I need to happen:-
Which of the following breeds are predisposed for primary (idiopathic epilepsy)?
a. German shepherd dog
b. Border Collie
c. Golden retriever
d. Boxer
e. All of the above
a,b,c,d,e will all have radio buttons, I need it so that the only combination of a,b and c will take the user to a certain page when they click the next button and all other combinations to another page.
Hope this makes sense.
Thanks
Nicodemas
04-17-2003, 04:31 AM
Using client-side javascript to validate answers to questions, and get the correct answer compared to the answer submitted is not very secure. I could look at the source code and get all the answers correct. Instead, you would want to use server-side technology to validate test answers.
cyberade
04-17-2003, 05:44 AM
If you still want to pursue a client-side approach then the following is a very basic example of what you may like to do.
Notes:
This is not a proper use of radio buttons. Checkboxes would be more appropriate.
This script does not claim to be perfect. It works and demonstrates the concept
but I'm sure there are many other (better) ways of achieving the same thing.
<html>
<head>
<title>Test Quiz</title>
<script>
function checkResult(){
if ( (document.quiz.a.checked == true) &&
(document.quiz.b.checked == true) &&
(document.quiz.c.checked == true) &&
(document.quiz.d.checked == false) &&
(document.quiz.e.checked == false)) {
self.location="nextquestion.html"
}
else {
self.location="wronganswer.html"
}
}
function reset(){
document.quiz.a.checked=false;
document.quiz.b.checked=false;
document.quiz.c.checked=false;
document.quiz.d.checked=false;
document.quiz.e.checked=false;
}
</script>
</head>
<body>
<p align="center">
Which of the following breeds are predisposed for primary (idiopathic epilepsy)?
<form name="quiz">
<!-- This table is a crude form of formatting -->
<table border=0>
<tr>
<td>
<input type="radio" name="a">a. German Shepherd Dog<br>
<input type="radio" name="b">b. Border Collie<br>
<input type="radio" name="c">c. Golden Retriever<br>
<input type="radio" name="d">d. Boxer<br>
<input type="radio" name="e">e. All of the above.<br>
</td>
</tr>
</table>
<br>
<input type="button" value="Submit" onClick="checkResult();">
<input type="button" value="Reset" onClick="reset(); return false">
</form>
</p>
</body>
</html>