im trying to create an online exam using django . i used a countdown javascript timer to tell when the time is done.
but the problem is : each time i move to the next question page the timer restarts.
is there a way to make the time go on even after refreshing the page ?
here is my template code (which has the timer)
<form name="counter"><input type="text" size="8"
name="d2"></form>
<script>
<!--
//
var milisec=0;
var seconds={{time}};
document.counter.d2.value={{time}};
function display()
{
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.counter.d2.value=seconds+"."+milisec
setTimeout("display()",1000)
}
display()
-->
</script>
thanks in advance
The easiest to implement would be to just pass the current timer value in the POST parameters, and restart the timer using that timer value on the next page.
Its probably better to use ajax (possibly through a django library like dajax) seems like a good way to go, and have the timer on one page (which continuously updates the questions as they move along).
Also, if this online test is used in any way (e.g., as a quiz grade for a class), you should record the initial and final timestamp on the server and go by that difference only (possibly giving several extra seconds to account for communication lag). In general you can’t trust that the javascript running hasn’t been altered. It can still be there as a convenience to let them know how much time is left, but remember that all client side java-script is easily modified by the user to give themselves more time.