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 Chriss Miller 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
Joined
Jan 8, 2003
Messages
291
Location
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



( keywords: javascript timing settimeout countdown keteracel )
 
Cool alternative, many thanks!

alej
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top