Results 1 to 3 of 3

Thread: countdown timer

  1. #1
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default countdown timer

    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

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Code:
    <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
    Last edited by Master_script_maker; 10-13-2008 at 05:02 PM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •