Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    JavaScript timer?

    Hello,
    I've found this simple time:

    PHP Code:

    var start=new Date();
    start=Date.parse(start)/1000;
    var 
    counts=5;
    function 
    CountDown(){
        var 
    now=new Date();
        
    now=Date.parse(now)/1000;
        var 
    x=parseInt(counts-(now-start),20);
        if(
    document.form1){document.form1.clock.value x;}
        if(
    x>0){
            
    timerID=setTimeout("CountDown()"100)
        }else{
            
    GetChat();
        }
    }

    window.setTimeout('CountDown()',100);
    var 
    ran Math.round(Math.random() * 899999) + 100000
    which I'm using to triger a simple ajax update on a web page.
    this seems to work fine.

    my question is, how can i have it start back at the beginning once it reachs 0 over and over again. so that it will continue refreshing the ajax content every 5 seconds?


    thanks in advance for your time!
    -Ken

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    maybe i should re-word this,

    I'm just looking for a way to triger an event every 5-10 seconds.

    is this possible?

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, i found what i was looking for:

    setInterval("GetChat()", 5000);

    does exactly what i needed.

    -Ken


  •  

    Posting Permissions

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