I have put the remaining timer on the exam page in an online examination system project which is fetching from the database. However, when I refresh it, the timer starts all over again. I want the timer, which has started, not to start again after a refresh and when the time is up, and the paper to be submitted automatically. Below, I have explained my code.
<form name="cd">
<input type="hidden" name="" id="timeExamLimit" value="<?php echo $selExamTimeLimit; ?>">
<label>Remaining Time : </label>
<input style="border:none;background-color: transparent;color:blue;font-size: 25px;" name="disp" type="text"
class="clock" id="txt" value="00:00" size="5" readonly="true"/>
</form>
//jQuery page
// Select Time Limit
var mins
var secs;
function cd() {
var timeExamLimit = $('#timeExamLimit').val();
mins = 1 * m("" + timeExamLimit); // change minutes here
secs = 0 + s(":01");
redo();
}
function m(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(0, i));
}
function s(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(i + 1, obj.length));
}
function dis(mins,secs) {
var disp;
if(mins <= 9) {
disp = " 0";
} else {
disp = " ";
}
disp += mins + ":";
if(secs <= 9) {
disp += "0" + secs;
} else {
disp += secs;
}
return(disp);
}
function redo() {
secs--;
if(secs == -1) {
secs = 59;
mins--;
}
document.cd.disp.value = dis(mins,secs);
if((mins == 0) && (secs == 0)) {
$('#examAction').val("autoSubmit");
$('#submitAnswerFrm').submit();
} else {
cd = setTimeout("redo()",1000);
}
}
function init() {
cd();
}
window.onload = init;