V24s

"Get Updates : Subscribe to our e-mail newsletter to receive updates........" "Good Luck frnds" Admission 2019 Application Form 2019 Colleges Entrance Exam 2019 Results 2019 Notification 2019 University Educational Jobs 2019 Government Jobs 2019

Search This Blog v24s guys

03 April, 2013

Call a JavaScript Function at Regular Intervals | Execute Function Every n Seconds

Introduction

Here I will explain how to call a JavaScript function at regular intervals of time or run/execute JavaScriptfunction every 10 seconds or execute JavaScript function at specific time in asp.net.

Description: 
   
In previous articles I explained 
jQuery get current page url and title, jQuery get url parameter values,Create tabbed Menu with rounded corners using CSS, jQuery shake image on mouse hover and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to call a JavaScript function at regular intervals of time in asp.net.

To execute function repeatedly with fixed time delay we have a function with two parameters calledsetInterval(functionname, timedelay).

In this function we need to call the required function in functionname field and we need to set the required time delay to execute the function in timedelay field. If you want to see it in example you need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Run JavaScript function at specific intervals of time</title>
<script type="text/javascript">
var count=0;
function changeColor() {

// Call function with 500 milliseconds gap
setInterval(starttimer, 500);
}
function starttimer() {
count += 1;
var oElem = document.getElementById("divtxt");
oElem.style.color = oElem.style.color == "red" ? "blue" : "red";
document.getElementById("lbltxt").innerHTML = "Your Time Starts: "+count;
}
</script>
</head>
<body>
<div id="divtxt">
<label id="lbltxt" style="font:bold 24px verdana" />
</div>
<button onclick="changeColor();">Start Timer</button>
</body>
</html>
Live Demo

For live demo click on below button


No comments:

Popular Posts

Recent Posts

Google Analytics