Example of using setTimeout() in Javascript

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

<TITLE>setTimeout() method</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
function displayAlert()
alert("5 seconds have elapsed since the button was clicked.")
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.
<INPUT TYPE = "button" VALUE = "5-second reminder"
NAME = "remind_button"
onClick = "timerID = setTimeout('displayAlert()',5000)">

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.