I have a problem with the following code , i put try ... catch around if statement , and display this error message :
'Question1' is undefined !
<html>
<head>
<title> Online Quiz </title>
<script type="text/JavaScript">
function checkAnswer(){
var correctAnswers=0;
var errorAnswers=0;
document.writeln("The Result : ");
try{
if(Question1.Q1[1].checked){
document.writeln("Q1 : Great !, True Answer is B !");
correctAnswers++;
}else{
errorAnswers++;
}
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.description + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
/*
if(Question2.Q2[2].checked){
document.writeln("Q2 : Great !, True Answer is C !");
correctAnswers++;
}else{
errorAnswers++;
}
if(Question3.Q3[0].checked){
document.writeln("Q3 : Great !, True Answer is A !");
correctAnswers++;
}else{
errorAnswers++;
}
if(Question4.Q4[0].checked){
document.writeln("G4 : Great !, True Answer is A !");
correctAnswers++;
}else{
errorAnswers++;
}
if(Question5.Q5[0].checked){
document.writeln("G5 : Great !, True Answer is A !");
correctAnswers++;
}else{
errorAnswers++;
}
*/
document.write("Your Correct Answers : "+correctAnswers);
document.write("Your InCorrect Answers : "+errorAnswers);
}
</script>
<style>
p{
font-size:24px;
font-style:italic;
color:blue;
}
</style>
</head>
<body>
<form method="get" id="QForm" >
<div id="Question1">
<p>1. What does CSS stand for ?</p>
<input type="radio" name="Q1" id="hello"/>a. Creative Style Sheets
<input type="radio" name="Q1" />b. Cascading Style Sheets
<input type="radio" name="Q1" />c. Computer Style Sheets
</div>
<hr/>
<div id="Question2">
<p>2. Which HTML tag is used to define an embedded styles ?</p>
<input type="radio" name="Q2" />a. < script >
<input type="radio" name="Q2" />b. < css >
<input type="radio" name="Q2" />c. < style >
</div>
<hr/>
<div id="Question3">
<p>3. Which HTML attribute is used to define inline styles ?</p>
<input type="radio" name="Q3" />a. style
<input type="radio" name="Q3" />b. class
<input type="radio" name="Q3" />c. styles
</div>
<hr/>
<div id="Question4">
<p>4. Which is the correct CSS syntax ?</p>
<input type="radio" name="Q4" />a. body {color: black}
<input type="radio" name="Q4" />b. {body:color=black(body}
<input type="radio" name="Q4" />c. {body;color:black}
</div>
<hr/>
<div id="Question5">
<p>5. Which property is used to change the background color ?</p>
<input type="radio" name="Q5" />a. background-color:
<input type="radio" name="Q5" />b. color:
<input type="radio" name="Q5" />c. bgcolor:
</div>
<hr/>
<div>
<input type="submit" name="subbutton" value="submit All" onclick="checkAnswer()" />
<input type="reset" name="rebutton" value="reset All"/>
</div>
</form>
</body>
</html>
i don't know what is the problem , please Help !