setTimeout and setInterval ?

What is the different between setTimeout and setInterval ?
And how do I stop them ?
superCombo2001Asked:
Who is Participating?
 
CJ_SConnect With a Mentor Commented:
Put this in between script tags:

var myInterval = null;
myInterval = setInterval("alert('hi')",1000);

and whenever you need to stop it you call:
clearInterval(myInterval);

instead of the alert('hi') you can use ANY javascript statement to be called.

regards,
CJ

0
 
CJ_SCommented:
setTimeout will act like a timer, and execute the statement after the specified interval. That will happen only once!
setInterval however will act as a true timer and execute the statement more than one time. After the specified interval the timer will be set back to 0 and count again. This will continue until you use the clearInterval method.

regards,
CJ
0
 
superCombo2001Author Commented:
how do I use clearInterval and setInterval ?
0
 
CyberSoftCommented:
Or if you want a number of statements to be run you can call a function :)

myInterval = setInteral("myfunction(), 1000)

Regards,
CyberSoft
0
 
CJ_SCommented:
>> ANY javascript statement
>> if you want a number of statements to be run you can call a function

---

the same
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.