tags:

views:

102

answers:

1

Hi, im using a plugin to do something ever 10 secs:

function status_updates(){
    $("p").everyTime(1000,function(i) { 
        if(i==10){
            alert("foo");
            // something here
        }else{
            $(this).html(i);    
        }
    });
}
status_updates();

where it says something here I need to add something to reset the timer but i dont know how. The plugin is here: http://jquery.offput.ca/every/ or if you know of an other way it would be much appreciated.

A: 

If you test with i==10, alert will be triggered just once.

Try with this:

function status_updates(){
    $("p").everyTime(1000,function(i) { 
        if(i % 10 == 0){
            alert("foo");
            // something here
        }else{
            $(this).html(i);    
        }
    });
}
status_updates();
systempuntoout
`i` might eventually overflow causing errors near the var size limit. Better to reset `i` to `0`.
Joel Potter
Hi Joel..why?It's upper bounded with 1000s.I don't even think this plugin permit to reset and restart.
systempuntoout
I assume `i` is the interval iteration counter. When `everyTime` is called without a count argument `i` is unbounded. Therefore, this loop function will be called every second, indefinitely. Eventually `i` would hit the javascript maximum value (about 1.8e+300 I think) and overflow to the minimum value. You'll get odd behavior when it overflows. Granted, at 1000 milliseconds it will take a long time, but you should still consider it.
Joel Potter
To reach the overflow you have to stay 1.8e+300 seconds on the same html page!Anyway feel free to help me if you know how to reset the counter for neatness.
systempuntoout