Example of using setTimeout() in Javascript

The setTimeout() method evaluates an expression after a specified number of milliseconds have elapsed.

<HTML>
<HEAD>
<TITLE>setTimeout() method</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
function displayAlert()
{ 
alert("5 seconds have elapsed since the button was clicked.")
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
Click the button on the left for a reminder in 5 seconds;
click the button on the right to cancel the reminder before
it is displayed.
<P>
<INPUT TYPE = "button" VALUE = "5-second reminder"
NAME = "remind_button"
onClick = "timerID = setTimeout('displayAlert()',5000)">
</FORM>
</BODY>
</HTML>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.