Loading ...

setInterval in JavaScript.

Who is online?  0 guests and 0 members
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

Contributor 2237  points  Contributor
  • Joined on: 9/24/2009
  • Posts: 172

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

Starter 695  points  Starter
  • Joined on: 6/17/2009
  • Posts: 14

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

Contributor 2237  points  Contributor
  • Joined on: 9/24/2009
  • Posts: 172

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

Starter 695  points  Starter
  • Joined on: 6/17/2009
  • Posts: 14
  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)