...

View Full Version : how to self-cancel window.setinterval ?



looka
02-01-2005, 09:05 PM
i have a function, which i would like to repeat with setinterval until some conditions are set.

myinterval = window.setInterval('myfunction();if(condition)window.cancelInterval(how)',tout);

okay, the question would be how can i pass the variable myinterval in that cancelinterval? or is any other way to get the intiger which leads to interval's canceling?

liorean
02-01-2005, 09:16 PM
var myinterval=setInterval(
function(){
myfunction();
if(cond)
clearInterval(myinterval);
},tout);

Puffin the Erb
02-01-2005, 09:17 PM
You need to use clearInterval( ) :


a=0;
function message()
{
a = a + 1;
alert(a);
if(a==10){alert("Cleared");window.clearInterval(myInterval);}
}

var myInterval = setInterval("message()",2000);

<edit reason="one-fingered typing">
You beat me to it lorean :)
</edit>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum