I want to resume the timer from the last saved value in database in my online test series portal. Format of storing time is in "hh:mm:ss". Timer has been implemented using javascript. I am storing the last time to a session and assigning it to a label based on condition. If the session is found to be null, the default time is taken for the corresponding paper. How do I resume the timer for the last saved time for a paper which is resumed ? I am attaching my javascript code of timer :
var myVar = setInterval(function () { myTimer() }, 1000);
var d = new Date();
var starttime = document.getElementById("<%= lbl_total_time.ClientID %>").innerHTML;
if (parseInt(starttime) < 10) {
starttime = "0" + starttime;
}
else {
starttime = starttime;
}
d.setHours(00, (parseInt(starttime) - 1), 59, 00);
function myTimer() {
if (d.getSeconds() <= 1)
d.setMinutes(d.getMinutes() - 1, 59, 00);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds() - 1;
if (h == 0 && m == 0 && s == 1) {
document.getElementById("<%= lbsendintime.ClientID %>").innerHTML = "00:00:00";
}
else {
if (h < 10) {
h = "0" + h;
}
if (m < 10) {
m = "0" + m;
}
if (s < 10) {
s = "0" + s;
}
document.getElementById("<%= lbsendintime.ClientID %>").innerHTML = h + ":" + m + ":" + s;
d.setMinutes(m, s);
}
}
.... Here, in the above code, field 'lbl_total_timer' is the label to which time is assigned from database. 'Thanks in advance...


Manikandan MurugesanRank #300 · 8.4K reputationPosted Jun 26, 2017, 1:06 AM EDT
The
tvariable won't return current countdown value, it returns the setTimeout id, which used to cancel the timeout function.So you have to use another variable to record down the current countdown seconds and in the countDownTimer function, instead of assign 60 to seconds, assign the recorded current countdown seconds.
Or you can use a setInterval function to do the countdown job and set a pause boolean value to denote the status:
Manikandan MurugesanRank #300 · 8.4K reputationPosted Jun 26, 2017, 1:08 AM EDT
Note, you should adjust timings in
Hope it'll help. I'd also recommend you reading tutorial or book on JavaScriptplayGetReadyaccording to your sounds. Also, onlya_5anda_1are loading.Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 27, 2017, 3:59 AM EDT