Time Setting Using JavaScript

 
JavaScript provides facility to deal with the time. SetInterval() function is used to call any assigned function after every given number of milliseconds. SetTimeout() function is used to delay for assigned number of milliseconds in calling assigned function. There are few examples of timings given below.
 
Example:
 
<html>

<head>

<title> Timing </title>

</head>

<script>

function talt()

{

var s=setTimeout(“alert(‘with in 1 Second ‘)”,1000)

}

function talt1()

{

var s=setTimeout(“alert(‘with in 5 Second ‘)”,5000)

}

</script>

<body bgcolor=blue text=yellow>

Click on button to view message <br>

<input type=”Button” Value=”Show me Timed Alert box in one second” onclick=”talt()”>

<input type=”Button” Value=”Show me Timed Alert box in Five second” onclick=”talt1()”>

</body>

</html>

Click here to view the result of this program on browser
 
 
Example:
 
<html>

<head>

<title> Timing </title></head>

<script>

function talt()

{

var s=setTimeout(“alert(‘with in Every 10 Second ‘)”,10000)

}

 

function talt1()

{

var s=setTimeout(“alert(‘with in Every 5 Second ‘)”,5000)

}

 

</script>

<body bgcolor=blue text=yellow>

Click on button to view message <br>

<input type=”Button” Value=”Show me Timed Alert box in Every Ten second” onclick=”setInterval(‘talt()’,10000)”>

<input type=”Button” Value=”Show me Timed Alert box in Every Five second” onclick=”setInterval(‘talt1()’,5000)”>

 

</body>

</html>