I have been using the below script to validate a 12 question quiz. The questions have 2 answers each, today I am making each question have 4 multiple choice answers,however the below script doesn't check the 2 extra multiple choice answers and hence can't continue.
How can I make the below script check for all 4 answers instead of 2 it presently is, I know it' around this part somewhere but am too much of a javascript n00b to remember:
How can I make the below script check for all 4 answers instead of 2 it presently is, I know it' around this part somewhere but am too much of a javascript n00b to remember:
Code:
var yesChoice = eval("document.quizForm.q" + i + "[0].checked");
var noChoice = eval("document.quizForm.q" + i + "[1].checked");
var noAnswer = eval("document.quizForm.q" + i + "[0].value");
var yesAnswer = eval("document.quizForm.q" + i + "[1].value");
Code:
<SCRIPT LANGUAGE="JavaScript"><!--
function validateAnswers() {
var correct = 0;
var wrong = 0;
var blank = 0;
for (var i=1;i<13;i++) {
var yesChoice = eval("document.quizForm.q" + i + "[0].checked");
var noChoice = eval("document.quizForm.q" + i + "[1].checked");
var noAnswer = eval("document.quizForm.q" + i + "[0].value");
var yesAnswer = eval("document.quizForm.q" + i + "[1].value");
if (yesChoice == noChoice)
blank++; // can't both be checked, thus must be both unchecked
else {
if ((yesChoice.toString() == yesAnswer) &&
(noChoice.toString() == noAnswer))
correct++;
else
wrong++;
}
}
document.quizForm.correct.value = correct;
document.quizForm.wrong.value = wrong;
document.quizForm.blank.value = blank;
}
//--></SCRIPT>
</body>