settimeout() function

by Sanju 2009-12-15 13:31:18

settimeout() function

setTimeout, a method of the window object, basically delays the execution of a function or statement until the specified time has passed. The basic syntax of this function is:

setTimeout("expression", delaytime)


"expression" is the function/statement you want delayed, and delaytime is the delay time, in milliseconds.

Example : 1

<script language=javascript>
document.df.hi.value=""
//simply clears the text box
function time(){
setTimeout("document.df.hi.value='Three seconds have gone!'",3000)
}
</script>
<form name="df">
<input type="text" name="hi" size="28">
<input type="button" value="Start" onClick="time()">
</form>


Result:







Example : 2

<script language=javascript>
var c=0
document.go.hi.value=""
function count()
{
document.go.hi.value=c
c=c+1
setTimeout("count()",1000)
}
</script>
<form name="go">
<input type="text" name="hi" size="12">
<input type="button" value="Start" onClick="count()">
</form>


Result:







Tagged in:

1147
like
0
dislike
0
mail
flag

You must LOGIN to add comments