I figure that I can't be that far off. This one should be solved quickly
pending the advice. There's something that I can't see or I'm overlooking.
This is a quiz that checks you answer, and if correct redirects you to a page
- if wrong redirects you to the wrong page. It has a time limit of 5 secs
that redirects you to a 'timeup' page once 5 secs passes.
Here's the code:
Code:
<html><head><title>Problem9</title>
<script type="text/javascript">
function attachHandlers()
{
var the_button = document.getElementById("chk_ans");
the_button.onclick=checkAnswer;
}
function attachTimeOut()
{
var the_tag = document.getElementsByTagName("a")[0];
the_tag.onclick=userTimeout
}
function userTimeout(){
var the_timeout = setTimeout("redirect();", 5000");
}
function checkAnswer()
{
var the_answer = document.getElementById("right_ans");
var the_opts = document.getElementsByTagName("input");
for (var i=0; i<the_opts.length; i++)
{
if (the_opts[i].nodeName.toLowerCase()=="input")
{
var the_sel = the_opts[i].checked;
}
}
if (the_sel==the_answer)
{
window.location.href="correct_page.html";
}
else
{
window.location.href="wrong_page.html";
}
setCookie(the_sel);
}
function setCookie(user_sel){
var user_answer = user_sel.value;
var the_cookie = user_answer;
document.cookie = "my_answer=" + escape(the_cookie);
}
function redirect()
{
window.location.href="time_up.html";
}
</script></head>
<body onLoad="attachHandlers();">
<p><a href="#">Click here once ready</a></p>
<div id="the_quiz">
<p>What's the capital of Illinois?</p>
<input type="radio" name="choice" value="Spring"
id="right_ans">Springfield<br>
<input type="radio" name="choice" value="Chicago">Chicago<br>
<input type="radio" name="choice" value="Lans">Lansing<br>
<input type="button" id="chk_ans" value="Check">
</div>
</body>
</html>
I'm hitting the 'check' button and nothing's happening. Any suggestions would be appreciated. Thanks.
|