Who is online? 134 guests and 0 members
Member login | Become a member
home »forums »asp.net topics »client side web development »setInterval in JavaScript.
Posted: 11/18/2009 4:32:59 AM
Hello,
I am using setInterval() but its not working properly.
Here is my code:-
<html> <head> <script type="text/javascript"> var i=0; function reFresh() { i++; document.write("welcome " + i ); } window.setInterval("reFresh()",1000); </script> </head> </html>
Can anyone tell me how can I run this program?
Posted: 11/18/2009 8:59:12 AM
mohit said: Hello,I am using setInterval() but its not working properly.Here is my code:- <html> <head> <script type="text/javascript"> var i=0; function reFresh() { i++; document.write("welcome " + i ); } window.setInterval("reFresh()",1000); </script> </head> </html>Can anyone tell me how can I run this program?
Hi mohit,
try it
<html> <body> <input type="textarea" id="clock" size="35" /> <script type="text/javascript"> var int=window.setInterval("clock()",50); var t=1; function clock() { document.getElementById("clock").value=t; t=t+1 } </script> <button onclick="int=window.clearInterval(int)">Stop interval</button> </body> </html>
Posted: 11/18/2009 10:35:38 PM
ajit said: Hi mohit, try it <html> <body> <input type="textarea" id="clock" size="35" /> <script type="text/javascript"> var int=window.setInterval("clock()",50); var t=1; function clock() { document.getElementById("clock").value=t; t=t+1 } </script> <button onclick="int=window.clearInterval(int)">Stop interval</button> </body> </html>
Thanks for reply.
Can you explain what is getElementById and why you used?
Posted: 11/19/2009 12:11:00 AM
mohit said: ajit said: Hi mohit, try it <html> <body> <input type="textarea" id="clock" size="35" /> <script type="text/javascript"> var int=window.setInterval("clock()",50); var t=1; function clock() { document.getElementById("clock").value=t; t=t+1 } </script> <button onclick="int=window.clearInterval(int)">Stop interval</button> </body> </html> Thanks for reply.Can you explain what is getElementById and why you used?
The getElementById() method returns a reference to the first object with the specified ID.
document.getElementById(id)
<html> <head> <script type="text/javascript"> function getValue() { var x=document.getElementById("myHeader"); alert(x.innerHTML); } </script> </head> <body> <h1 id="myHeader" onclick="getValue()">Check getElementById function </h1> <p>Click on the header to alert its value</p> </body> </html>
Hope this will help you..