SetTimeOut and ClearInterval

[Total: 0    Average: 0/5]

This shows how to set a function to be called 1 time in the future.

Body Code:

<script type=text/javascript>
var A = null; // preset the timer object to null.
var B = null; // preset the timer object to null.
var messageA = "I was first";
var messageB = "I'm always last";
A = setTimeout("callMe(messageA)",1000); // wait 1 full second (1000 msecs) and then call "callMe()"
B = setTimeout("callMe(messageB)",2000); // wait 2 seconds.
function callMe(_v) {
  clearInterval(B);
  alert("I have been called: "+_v);
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *