Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

setTimeout and setInterval ?

What is the different between setTimeout and setInterval ?
And how do I stop them ?
0
superCombo2001
Asked:
superCombo2001
  • 3
1 Solution
 
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
 
CJ_SCommented:
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now