CaTaLinU Posted September 3, 2011 Share Posted September 3, 2011 I need a script which it counts the seconds automaticaly , without a start button or something else when you refresh the page , the counter starts again from 0 seconds automatically can someone help me?? Sorry for my bad english Quote Link to comment https://forums.phpfreaks.com/topic/246352-count-up-script/ Share on other sites More sharing options...
flappy_warbucks Posted September 3, 2011 Share Posted September 3, 2011 You would need javascript for that. <script type="text/javascript"> function timeMsg() { var t=setTimeout("alertMsg()",3000); // 3000 microsecond = 3 seconds. } function alertMsg() { alert("Hello"); // after 3 seconds, this alert dialog will be displayed. You could get rid of this, and have the script do whatever you need it to do. } </script> Quote Link to comment https://forums.phpfreaks.com/topic/246352-count-up-script/#findComment-1265084 Share on other sites More sharing options...
CaTaLinU Posted September 3, 2011 Author Share Posted September 3, 2011 yes , a javascript can someone help me? Quote Link to comment https://forums.phpfreaks.com/topic/246352-count-up-script/#findComment-1265097 Share on other sites More sharing options...
JonnoTheDev Posted September 7, 2011 Share Posted September 7, 2011 <html> <head> <script type="text/javascript"> var c = 0; var t; var timer_is_on = 0; function timed_count() { document.getElementById('counter').innerHTML = c; c = c+1; t = setTimeout('timed_count()',1000); } function do_timer() { if(!timer_is_on) { timer_is_on = 1; timed_count(); } } window.onload = do_timer; </script> </head> <body> <div id="counter">0</div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/246352-count-up-script/#findComment-1266445 Share on other sites More sharing options...
Adam Posted September 8, 2011 Share Posted September 8, 2011 Better to use an interval in this case: var counter; var count = 1; function do_count() { document.getElementById('counter').innerHTML = count++; } window.onload = function() { counter = setInterval('do_count()', 1000); } Quote Link to comment https://forums.phpfreaks.com/topic/246352-count-up-script/#findComment-1266858 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.