home »forums »asp.net topics »client side web development »setInterval in JavaScript.

setInterval in JavaScript.

Posts under the topic: setInterval in JavaScript.

Posted: 11/18/2009 4:32:59 AM

mohit mohit
Starter
  • 776 points  Starter
  • Joined on: 9/24/2009
  • Posts:40

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

ajit ajit
Starter
  • 613 points  Starter
  • Joined on: 6/17/2009
  • Posts:12

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

mohit mohit
Starter
  • 776 points  Starter
  • Joined on: 9/24/2009
  • Posts:40

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

ajit ajit
Starter
  • 613 points  Starter
  • Joined on: 6/17/2009
  • Posts:12
answered  Answered

 

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.

Syntax

document.getElementById(id)

Example.

 

<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..


Page 1 of 1 (4 items)