Introduction:
Here I will explain how to use JavaScript setTimeout function with example. JavaScript setTimeout() function is used to execute functions at regular intervals of time. Suppose if we want to execute one JavaScript function for every 10 seconds or for a specific time we can use JavaScript setTimeout function to achieve this functionalit.
Description:
In previous articles I explained Start and Stop timer in JavaScript, Show user current location on Google map, Regular expression to validate file upload extension and many articles relating to jQuery, JavaScript. Now I will explain how to use JavaScript setTimeout() function with example.
Here I will explain how to use JavaScript setTimeout function with example. JavaScript setTimeout() function is used to execute functions at regular intervals of time. Suppose if we want to execute one JavaScript function for every 10 seconds or for a specific time we can use JavaScript setTimeout function to achieve this functionalit.
Description:
In previous articles I explained Start and Stop timer in JavaScript, Show user current location on Google map, Regular expression to validate file upload extension and many articles relating to jQuery, JavaScript. Now I will explain how to use JavaScript setTimeout() function with example.
JavaScript setTimeout() function is same
as jQuery setInterval() function . We can use setTimeout function in
different ways like as shown below
Method 1:
setTimeout(yourfunction(),
timeinterval);
function yourfunction() {
// your code here
}
|
Method 2:
setTimeout(function(){// your
code here
},
timeinterval);
|
For complete example
check below code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript
display current time on webpage</title>
<script type="text/javascript">
function ShowCurrentTime() {
var dt = new Date();
document.getElementById("lblTime").innerHTML =
dt.toLocaleTimeString();
setTimeout("ShowCurrentTime()", 1000); // Here 1000(milliseconds) means one 1 Sec
}
</script>
</head>
<body onload="ShowCurrentTime()">
<div>
JavaScript
Display current time second by second:
<label id="lblTime" style=" font-weight:bold"></label>
</div>
</body>
</html>
|
Live Demo
Check below time for
live demo it will run for every one second
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
2 comments :
hai suresh
i developed three tier tier architecture web application using using c sharp asp.net and sql 2008
i want to set session state time out in web config...
i set session time web config
but its unexpected logout every frequent times
how to solve it please reply me to this mail id..
email id: sureshemanip@gmail.com
how to validate firstname, emailid in javascript??
Note: Only a member of this blog may post a comment.