Hi in my javascript i need to increase an int value by one after every 5 seconds. How to do this? The script should keep increasing until the user moves away from the page.

This could be easily done using the setInterval() method.

Simple example...

<span id="total">0</span>

<script>
var x = 0;
var int=self.setInterval(function(){count()},5000);

function count(){
  x++;
  document.getElementById("total").innerHTML=x;
}
<script>

Try on jsFiddle

commented: Thanks +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.