I am developing a online quiz website in php. I've done most of it-questions get selected randomly from database one at a time, and i have the following php files:
database.php, index.php, login.php, logout.php, quiz.php, result.php.
- When the user login,He wil be redirected to index page(home page) containing quiz and result,
- then when user select quiz he wil be redirected to quiz.php where he can take the quiz
- later when user click on finish, user will be redirected to home page where he can see his result,this things are working fine.
Now i want to attach a countdown timer(using minutes and seconds left) which will be continuously displayed while user is taking the quiz.
When timer expires(reaches 0)the quiz.php should appear blank and should be redirected to home page,where the user can see the result.
I have the following countdown timer code in but i am not getting how to implement it,So can someone help how to implement .
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language ="javascript" >
var tim;
var min = 20;
var sec = 60;
var f = new Date();
function f1() {
f2();
document.getElementById("starttime").innerHTML = "Your started your Exam at " + f.getHours() + ":" + f.getMinutes();
}
function f2() {
if (parseInt(sec) > 0) {
sec = parseInt(sec) - 1;
document.getElementById("showtime").innerHTML = "Your Left Time is :"+min+" Minutes ," + sec+" Seconds";
tim = setTimeout("f2()", 1000);
}
else {
if (parseInt(sec) == 0) {
min = parseInt(min) - 1;
if (parseInt(min) == 0) {
clearTimeout(tim);
location.href = "default5.aspx";
}
else {
sec = 60;
document.getElementById("showtime").innerHTML = "Your Left Time is :" + min + " Minutes ," + sec + " Seconds";
tim = setTimeout("f2()", 1000);
}
}
}
}
</script>
</head>
<body onload="f1()" >
<form id="form1" runat="server">
<div>
<table width="100%" align="center">
<tr>
<td colspan="2">
<h2>This is head part for showing timer and all other details</h2>
</td>
</tr>
<tr>
<td>
<div id="starttime"></div><br />
<div id="endtime"></div><br />
<div id="showtime"></div>
</td>
</tr>
<tr>
<td>
<br />
</td>
</tr>
</table>
<br />
</div>
</form>
</body>
</html>
how to implement countdown timer in phpyet all the code given is javascript. Without recording the start time what is to stop the user reloading the page at which point the timer begins again?