Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delay

Status
Not open for further replies.

almoes

Programmer
Jan 8, 2003
291
0
0
US
Hi all!

Is there any javascript function I could use to introduce a time delay in my code??

thanks,
alej
 
yup

The timer functions.

Known is handfull, Unknown is worldfull
 
banner.png


The
Code:
window.setTimeout("functionName()",delay);
function should suffice. Where functionName is any function or javascript code and delay is an integer value of time in milliseconds -- i.e. 1000 corresponds to 1 second.

Example:

Code:
<html>
<head>
  <title>timer example - provided by keteracel.com</title>
  <script type=&quot;text/javascript&quot;>
    function countdown(tick) {
      if(tick > -1) {
	document.one.ticker.value = tick;      
	tick -= 1;
	window.setTimeout(&quot;countdown(&quot; + tick + &quot;);&quot;,1000);
      }
      else {
        alert(&quot;Finished counting down...&quot;);
      }
    }
  </script>
</head>
<body onLoad=&quot;countdown(30);&quot;>
  <form name=&quot;one&quot;>
    <input name=&quot;ticker&quot; type=&quot;text&quot; size=&quot;2&quot; value=&quot;30&quot;>
  </form>
</body>
</html>

This example simply displays a text area with a number which counts down 30 seconds, before displaying an alert saying it has finished.

Hope this helps,

keteracel



[sub]( keywords: javascript timing settimeout countdown keteracel )[/sub]
 
Cool alternative, many thanks!

alej
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top