Resume Javascript Timer from database value

Jun 26 2017 4:30 AM
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 :
 
<script type="text/javascript">
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);
}
}
</script>
 
.... Here, in the above code, field 'lbl_total_timer' is the label to which time is assigned from database. 'Thanks in advance...
 

Answers (3)