I have written a code in javascript for a timer which submits the form when time is up. The problem is if the user refreshes the page the timer is reset how can i avoid this from happening?
<script type="text/javascript">
var total_seconds = 6*1;
var c_minutes = parseInt(total_seconds/60);
var c_seconds = parseInt(total_seconds%60);
function CheckTime()
{
document.getElementById("quiz-time-left").innerHTML
= 'Time Left: ' + c_minutes + ' minutes ' + c_seconds + ' seconds ' ;
if(total_seconds <=0)
{
document.forms['quiz'].submit();
}
else
{
total_seconds = total_seconds -1;
c_minutes = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",1000);
}
}
setTimeout("CheckTime()",0);
</script>
Aucun commentaire:
Enregistrer un commentaire