homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
simple Timeout & clear
sssweb




msg:4532622
 9:09 pm on Jan 2, 2013 (gmt 0)

I'm having trouble with what should be a simple Timeout and clear. Here's my code:

function test() {
var Timer = setTimeout(function() {
alert("hello");
}, 1000);
}

test();

The code runs in a slideshow, and when the slide transitions out, I clear the timeout using:

clearTimeout(Timer);

For some reason, the clear causes the slideshow navigation to hang and remain stuck on the current slide. Is there something wrong with my code? Better yet, can I do this w/o coding the Timeout as a function w/in a function? That would likely solve it.

 

sssweb




msg:4532637
 9:25 pm on Jan 2, 2013 (gmt 0)

I got it. Timer needs to be defined outside the function:

var Timer;
function test() {
Timer = setTimeout(function() {
alert("hello");
}, 1000);
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved