Juankayce56
02-23-2004, 10:30 PM
Sorry this is my first time using the forum!!!
My problem is i keep getting an error saying that document.quiz.studentAnswer1.value is num even though it's there and it's a hidden field!! i think the problem is in my function scoreQuiz()
here is my code i can't get it to work can anybody help!!
Thanks
<HTML>
<HEAD>
<TITLE>Math Quiz</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function recordAnswer(question, answer) {
if (question == 1)
document.quiz.studentAnswer1.value = answer;
else if (question == 2)
document.quiz.studentAnswer2.value = answer;
else if (question == 3)
document.quiz.studentAnswer3.value = answer;
}
function scoreQuiz() {
if (document.quiz.studentAnswer1.value == "" || document.quiz.studentAnswer2.value == "" || document.quiz.studentAnswer3.value == "") {
alert("You must answer all of the questions before scoring the quiz.");
/* code here to "cancel" the onSubmit event handler*/
return false;
}
var correct = 0;
if (document.quiz.studentAnswer1.value == document.quiz.answer1.value)
++correct;
if (document.quiz.studentAnswer2.value == document.quiz.answer2.value)
++correct;
if (document.quiz.studentAnswer3.value == document.quiz.answer3.value)
++correct;
alert("You scored " + correct + " answers correctly.");
/* code here to have the onSubmit event handler fire off*/
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Math Quiz</H2><P>
<P>Select the correct answer to the following math problems, then select the Score Quiz button.</P>
<FORM NAME="quiz" onSubmit="return scoreQuiz();">
<P><B>1.</B> 84 divided by 7 is equal to _____.</P>
<P><INPUT TYPE=radio NAME=question1 VALUE="6" onClick="recordAnswer(1, this.value);">6<BR>
<INPUT TYPE=radio NAME=question1 VALUE="7" onClick="recordAnswer(1, this.value);">7<BR>
<INPUT TYPE=radio NAME=question1 VALUE="9" onClick="recordAnswer(1, this.value);">9<BR>
<INPUT TYPE=radio NAME=question1 VALUE="12" onClick="recordAnswer(1, this.value);">12</P>
<P><B>2.</B> What is the value of x in the equation <B>x * 12 = 156</B>.</P>
<P><INPUT TYPE=radio NAME=question2 VALUE="5" onClick="recordAnswer(2, this.value);">5<BR>
<INPUT TYPE=radio NAME=question2 VALUE="11" onClick="recordAnswer(2, this.value);">11<BR>
<INPUT TYPE=radio NAME=question2 VALUE="13" onClick="recordAnswer(2, this.value);">13<BR>
<INPUT TYPE=radio NAME=question2 VALUE="19" onClick="recordAnswer(2, this.value);">19</P>
<P><B>3.</B> What is the square root of 196?</P>
<P><INPUT TYPE=radio NAME=question3 VALUE="7" onClick="recordAnswer(3, this.value);">7<BR>
<INPUT TYPE=radio NAME=question3 VALUE="14" onClick="recordAnswer(3, this.value);">14<BR>
<INPUT TYPE=radio NAME=question3 VALUE="28" onClick="recordAnswer(3, this.value);">28<BR>
<INPUT TYPE=radio NAME=question3 VALUE="98" onClick="recordAnswer(3, this.value);">98</P>
<P><INPUT TYPE="submit" VALUE=" Score Quiz "></P>
<Input Type ="hidden" name "studentAnswer1" value ="12">
<Input Type ="hidden" name "studentAnswer2" value ="13">
<Input Type ="hidden" name "studentAnswer3" value ="14">
</FORM>
</BODY>
</HTML>
My problem is i keep getting an error saying that document.quiz.studentAnswer1.value is num even though it's there and it's a hidden field!! i think the problem is in my function scoreQuiz()
here is my code i can't get it to work can anybody help!!
Thanks
<HTML>
<HEAD>
<TITLE>Math Quiz</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function recordAnswer(question, answer) {
if (question == 1)
document.quiz.studentAnswer1.value = answer;
else if (question == 2)
document.quiz.studentAnswer2.value = answer;
else if (question == 3)
document.quiz.studentAnswer3.value = answer;
}
function scoreQuiz() {
if (document.quiz.studentAnswer1.value == "" || document.quiz.studentAnswer2.value == "" || document.quiz.studentAnswer3.value == "") {
alert("You must answer all of the questions before scoring the quiz.");
/* code here to "cancel" the onSubmit event handler*/
return false;
}
var correct = 0;
if (document.quiz.studentAnswer1.value == document.quiz.answer1.value)
++correct;
if (document.quiz.studentAnswer2.value == document.quiz.answer2.value)
++correct;
if (document.quiz.studentAnswer3.value == document.quiz.answer3.value)
++correct;
alert("You scored " + correct + " answers correctly.");
/* code here to have the onSubmit event handler fire off*/
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Math Quiz</H2><P>
<P>Select the correct answer to the following math problems, then select the Score Quiz button.</P>
<FORM NAME="quiz" onSubmit="return scoreQuiz();">
<P><B>1.</B> 84 divided by 7 is equal to _____.</P>
<P><INPUT TYPE=radio NAME=question1 VALUE="6" onClick="recordAnswer(1, this.value);">6<BR>
<INPUT TYPE=radio NAME=question1 VALUE="7" onClick="recordAnswer(1, this.value);">7<BR>
<INPUT TYPE=radio NAME=question1 VALUE="9" onClick="recordAnswer(1, this.value);">9<BR>
<INPUT TYPE=radio NAME=question1 VALUE="12" onClick="recordAnswer(1, this.value);">12</P>
<P><B>2.</B> What is the value of x in the equation <B>x * 12 = 156</B>.</P>
<P><INPUT TYPE=radio NAME=question2 VALUE="5" onClick="recordAnswer(2, this.value);">5<BR>
<INPUT TYPE=radio NAME=question2 VALUE="11" onClick="recordAnswer(2, this.value);">11<BR>
<INPUT TYPE=radio NAME=question2 VALUE="13" onClick="recordAnswer(2, this.value);">13<BR>
<INPUT TYPE=radio NAME=question2 VALUE="19" onClick="recordAnswer(2, this.value);">19</P>
<P><B>3.</B> What is the square root of 196?</P>
<P><INPUT TYPE=radio NAME=question3 VALUE="7" onClick="recordAnswer(3, this.value);">7<BR>
<INPUT TYPE=radio NAME=question3 VALUE="14" onClick="recordAnswer(3, this.value);">14<BR>
<INPUT TYPE=radio NAME=question3 VALUE="28" onClick="recordAnswer(3, this.value);">28<BR>
<INPUT TYPE=radio NAME=question3 VALUE="98" onClick="recordAnswer(3, this.value);">98</P>
<P><INPUT TYPE="submit" VALUE=" Score Quiz "></P>
<Input Type ="hidden" name "studentAnswer1" value ="12">
<Input Type ="hidden" name "studentAnswer2" value ="13">
<Input Type ="hidden" name "studentAnswer3" value ="14">
</FORM>
</BODY>
</HTML>