amalosoul Posted December 8, 2006 Share Posted December 8, 2006 Why doesn't this update the time without my having to refresh the page?function startTime(hour,mins,sec){var today=new Date()var h=today.getHours()var m=today.getMinutes()var s=today.getSeconds()// add a zero in front of numbers<10m=checkTime(m)s=checkTime(s)document.getElementById('txt').innerHTML=h+":"+m+":"+st=setTimeout('startTime(hour,mins,sec)',500)}//then I call this function when the page loads, and add the div elementThank you! Quote Link to comment Share on other sites More sharing options...
tomfmason Posted December 8, 2006 Share Posted December 8, 2006 Well you are going to have multiple instances of the timeout if you don't use clearInterval. Personally I would create another function for the updates.. Here is an example.[code]function MyFunction(hour, mins, sec) { clearInterval(t); startTimer(hour, mins, sec);}[/code]Now just change the function called in your setTimeout to Myfunction.The reason that I place the clearInterval outside of the startTimer function is that it may cause an error when the page first loads because the variable t is not an interval.Good Luck,Tom Quote Link to comment Share on other sites More sharing options...
amalosoul Posted December 8, 2006 Author Share Posted December 8, 2006 Thank you I will try this idea:)! Quote Link to comment 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.