svgmx5 Posted September 28, 2010 Share Posted September 28, 2010 has anyone made a counter before that increases every 2 seconds? it doe not have to increase every time a user clicks on something, it just has to increase by itself every 2 seconds Quote Link to comment https://forums.phpfreaks.com/topic/214589-help-creating-a-counter/ Share on other sites More sharing options...
gizmola Posted September 28, 2010 Share Posted September 28, 2010 Sure, you can use the javascript setInterval function. Here's a sample that sets up a form element and updates it every 2 seconds. <br /> function init() {<br /> document.forms["form1"].counter.value=0;<br /> }<br /> <br /> function updateCounter(){<br /> document.forms["form1"].counter.value++;<br /> }<br /> <br /> window.onload=function(){<br /> init();<br /> setInterval(updateCounter, 2000);<br /> }<br /> </pre> <form name="form1"> Counter: </form> <br><b Quote Link to comment https://forums.phpfreaks.com/topic/214589-help-creating-a-counter/#findComment-1116645 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.