PDA

View Full Version : very very simple clearInterval function not working


redhead
04-18-2003, 06:51 PM
greetings... back to newb i go ;)

this is an extremely simple script (just scrolls an iframe down), so, i was expecting it to work without hiccup. but... as is always the way, when you think its gonna work, it doesnt.

firstly, here's the script:function scrollDown() {
var scroll = setInterval("window.content.scrollBy(0,2);",100);
}

function stop() {
clearInterval(scroll);
}there we go.. nothing life changingly revolutionary about that. but... when stop() is called, the iframe doesnt stop scrolling down... i dont get an error... it just... carries on scrolling.

there must be something elementary i am missing... ive never managed to mess up a script this simple.

smeagol
04-18-2003, 07:33 PM
You'll beat yourself up over this.....but the problem is with the Scope of the variable named "scroll". It's defined within the scope of the function "scrollDown()", so the function "stop()" cannot access it.

Declare scroll as a global variable instead of within the function scrollDown() and you will be able to stop it.

Just one of those things we all do from time to time....forget the scope of the variable.

redhead
04-18-2003, 07:43 PM
*kicks self*

heh... im clearly having a bad day... i usually notice things like that ;)

thanks man... sorted it now :)

(i wonder if i should delete this thread so nobody sees my mistake... lol... nah;))

smeagol
04-18-2003, 07:47 PM
We all have those days, my friend.......believe me....