PDA

View Full Version : countdown timer



GoogleQuality
10-13-2008, 03:54 PM
hi

how can i use javascript to create a countdown timer

i'm creating online exam and i want a timer that counts for an hour then do some php fucntions

thanks

Master_script_maker
10-13-2008, 04:49 PM
<script type="text/javascript">
var t;
var v=new Array(1, 0, 0, 0, 0);
function timer() {
v[2]--;
for (i=2; i>0;i--) {
if (v[i]<0) {
v[i]=59;
v[i-1]--;
}
}
if (v[0]==0&&v[1]==0&&v[2]==0) {
//timer is over
} else {
t=setTimeout("timer()", 1000);
v[3]=v[1]<10?"0"+v[1]:v[1];
v[4]=v[2]<10?"0"+v[2]:v[2];
document.getElementById("time").innerHTML=v[0]+':'+v[3]+':'+v[4];
}
}
</script>
<div id="time"></div>
and run timer() on body load

GoogleQuality
10-13-2008, 05:27 PM
thank very much

last question

is it possible to keep the state of the current time value

becouse the online exam will be seperated in more than 1 page so i want to keep the time while moving from page to page ( i want to keep it's value for example i'm at page two at time 00:40 and now i will go to page 2 so the time should continue from 00:40 until i reach 00:00 where i will execute my event )

thanks again