Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Timer Question

  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Timer Question

    Hi
    This timer counts down from 15 seconds and stops, I want the timer to reset itself and start the countdown over again, indefinitely. Thanks Papajo



    Code:
    var refreshinterval=15
    var displaycountdown="yes"
    
    var starttime
    var nowtime
    var reloadseconds=0
    var secondssinceloaded=0
    
    function starttime() {
    	starttime=new Date()
    	starttime=starttime.getTime()
        countdown()
    }
    
    function countdown() {
    	nowtime= new Date()
    	nowtime=nowtime.getTime()
    	secondssinceloaded=(nowtime-starttime)/1000
    	reloadseconds=Math.round(refreshinterval-secondssinceloaded)
    	if (refreshinterval>=secondssinceloaded) {
            var timer=setTimeout("countdown()",1000)
    		if (displaycountdown=="yes") {
    document.form.show.value=""+reloadseconds+ "";
    		}}}
    <form name="form">
    <input type="text" name="show" size="3">
    <input type='button' onClick='starttime()' value='Start'></form>

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    It's as easy as calling starttime() again in an else statement at the very end.

    It won't work of course, because you are overwriting that function with other stuff. Don't use the same names for functions and variables.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •