I have been playing around with this code for far too long. The code worked fine at first, but when I tried to validate under strict I got a "name" attribute in the form element not valid, so I took it out. Now its keeps saying that document.quiz is not declared. Not sure how to declare of if I should change the .JS file. Any help would be great.
<head>
<title>Online Aptitude Quiz: Page</title>
<link href="./styles/quiz.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./scripts/functions.js"></script>
<script type="text/javascript">
var seconds = 0;
var clockId;
var quizclock;
function runClock() {
seconds++;
document.quiz.quizclock.value= seconds;
}
function startClock() {
showQuiz();
clockId = setInterval ("runClock()",1000);
}
var timer;
function stopClock() {
clearInterval (clockId);
correctAns = gradeQuiz();
alert( "You have " + correctAns + " correct of 5 in " + seconds + " seconds.");
}
</script></head>
<body>
<form id="quiz" action ="">
<div id="header">
<p><img src="./images/oae.jpg" alt="Online Aptitude Exam" />
<span>Grunwald Testing, Inc.</span><br />
1101 Science Drive<br />
Oakdale, CA 88191
</p>
</div>
<div id="intro">
<p>This is a timed quiz of intelligence and perception. Your final score will
be based on the number of correct answers and the time required to submit those
answers.</p>
<p>To start the quiz, click the <b>Start Quiz</b> button below, which will
reveal the first page of quiz questions and start the timer. When you have
completed the questions, click the <b>Submit Answers</b> button on the quiz
form.</p>
<p id="buttons">
<input type="button" onclick="startClock()" value="Start Quiz" />
<br />
<input id="quizclock" name="quizclock" value="0" />
</p>
</div>
<div id="questions">
<h1>Page 1: Pattern Recognition</h1>
<table id="quiztable">
<tr>
<th rowspan="3">1.</th>
<td colspan="2">Enter the next number in this sequence: 1, 3, 4, 7, 11, 18, ...</td>
</tr>
<tr>
<td><input type="radio" name="q1" />a) 22</td>
<td><input type="radio" name="q1" />c) 28</td>
</tr>
<tr>
<td id="cor1"><input type="radio" name="q1" />b) 29</td>
<td><input type="radio" name="q1" />d) 32</td>
</tr>
<tr>
<th rowspan="3">2.</th>
<td colspan="2">Enter the final three numbers in this sequence: 8, 5, 4, 9, 1, 7, 6, ...</td>
</tr>
<tr>
<td id="cor2"><input type="radio" name="q2" />a) 10, 3, 2</td>
<td><input type="radio" name="q2" />c) 2, 3, 10</td>
</tr>
<tr>
<td><input type="radio" name="q2" />b) 2, 10, 3</td>
<td><input type="radio" name="q2" />d) 10, 2, 3</td>
</tr>
<tr>
<th rowspan="3">3.</th>
<td colspan="2">Enter the next letter in this sequence: j, f, m, a, m, j, j, ...</td>
</tr>
<tr>
<td><input type="radio" name="q3" />a) j</td>
<td><input type="radio" name="q3" />c) f</td>
</tr>
<tr>
<td><input type="radio" name="q3" />b) m</td>
<td id="cor3"><input type="radio" name="q3" />d) a</td>
</tr>
<tr>
<th rowspan="3">4.</th>
<td colspan="2">What letter in this set does not belong?: A, B, D, G, J, S, O</td>
</tr>
<tr>
<td id="cor4"><input type="radio" name="q4" />a) A</td>
<td><input type="radio" name="q4" />c) J</td>
</tr>
<tr>
<td><input type="radio" name="q4" />b) B</td>
<td><input type="radio" name="q4" />d) O</td>
</tr>
<tr>
<th rowspan="3">5.</th>
<td colspan="2">What is the next figure in the following sequence?:<br />
<img src="./images/figures.jpg" alt="" />
</td>
</tr>
<tr>
<td><input type="radio" name="q5" />a) <img src="./images/figa.jpg" alt="" /></td>
<td><input type="radio" name="q5" />c) <img src="./images/figc.jpg" alt="" /></td>
</tr>
<tr>
<td><input type="radio" name="q5" />b) <img src="./images/figb.jpg" alt="" /></td>
<td id="cor5"><input type="radio" name="q5" />d) <img src="./images/figd.jpg" alt="" /></td>
</tr>
<tr>
<td style="text-align: center;" colspan="3">
<hr />
<input type="button" onclick="stopClock()" value="Submit Answers" />
</td>
</tr>
</table>
</div>
</form>
<p>
<a href= "../index.html">Home</a>
</p>
</body>
</html>
And her is the .JS file
nction showQuiz() {
document.getElementById("quiztable").style.visibility="visible";
}
function hideQuiz() {
document.getElementById("quiztable").style.visibility="hidden";
}
function gradeQuiz() {
correct=0;
if (document.quiz.q1[2].checked) correct++;
if (document.quiz.q2[0].checked) correct++;
if (document.quiz.q3[3].checked) correct++;
if (document.quiz.q4[0].checked) correct++;
if (document.quiz.q5[3].checked) correct++;
document.getElementById("cor1").style.backgroundColor="yellow";
document.getElementById("cor2").style.backgroundColor="yellow";
document.getElementById("cor3").style.backgroundColor="yellow";
document.getElementById("cor4").style.backgroundColor="yellow";
document.getElementById("cor5").style.backgroundColor="yellow";
for (i=0; i<document.quiz.elements.length; i++) document.quiz.elements[i].disabled=true;
return correct;
}