Jump to content

Clock?


Twango

Recommended Posts

Hey, why isnt this repeating?<!--Simple clock that will be at the bottom right & left of the screen--><body onload="clock()"/><head><script type="text/javascript">var d=new Date();function clock(){var o=setTimeout("tad()",1000);var t=setTimeout("sp()",1001);clock();}function tad(){var day=d.getDay();var dy=["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"];var days=dy[day];var day2=d.getDate();var mon=d.getMonth() + 1;var yr=d.getYear() + 1900;document.getElementById('text1').innerHTML=days + " " + mon + "/" + day2 + "/" + yr + " ";} function sp(){var s=d.getSeconds();if (s < 10){s="0" + s;}else{}var m=d.getMinutes();if (m < 10){m="0" + s;}else{}var h=d.getHours;var sph=["NULL","1","2","3","4","5","6","7","8","9","10","11","12","1","2","3","4","5","6","7","8","9","10","11","12"];h=sph[h];var apm=["NULL","AM","AM","AM","AM","AM","AM","AM","AM","AM","AM","AM","NOON","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM"]var ap=apm[d.getHours()];document.getElementById('text2').innerHTML=h + ":" + m + ":" + s + " " + ap;}</script></head><div id="clock1" style="background-color:black;color:white;position:fixed;left:0;bottom:0"><b id="text1">Please Wait...</b></div><div id="clock2" style="background-color:black;color:white;position:fixed;right:0;bottom:0"><b id="text2">Please wait...</b></div>

Link to comment
Share on other sites

clock() calls clock() in an infinite recurse. It will never stop. There is no delay between calls. The call is instantaneous. Every time clock runs, it resets both timers. So their functions never get called.What you want is for tad() to call tad() on a timer. Same with sp()

Link to comment
Share on other sites

Hmm, i tried <!--Simple clock that will be at the bottom right & left of the screen--><body onload="tad()"></body><body onLoad="sp()"><head><script type="text/javascript">var d=new Date();function tad(){var day=d.getDay();var dy=["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"];var days=dy[day];var day2=d.getDate();var mon=d.getMonth() + 1;var yr=d.getYear() + 1900;document.getElementById('text1').innerHTML=days + " " + mon + "/" + day2 + "/" + yr + " ";var reset2=setTimeout("tad()",1000);} function sp(){var reset3=setTimeout("sp()",1000);var s=d.getSeconds();if (s < 10){s="0" + s;}else{}var m=d.getMinutes();if (m < 10){m="0" + m;}else{}var h=d.getHours();var sph=["NULL","1","2","3","4","5","6","7","8","9","10","11","12","1","2","3","4","5","6","7","8","9","10","11","12"];h=sph[h];var apm=["NULL","AM","AM","AM","AM","AM","AM","AM","AM","AM","AM","AM","NOON","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM","PM"];var ap=apm[d.getHours()];document.getElementById('text2').innerHTML=h + ":" + m + ":" + s + " " + ap;}</script></head><div id="clock1" style="background-color:black;color:white;position:fixed;left:0;bottom:0"><b id="text1">Please Wait...</b></div><div id="clock2" style="background-color:black;color:white;position:fixed;right:0;bottom:0"><b id="text2">Please wait...</b></div>but that's not working. why?

Link to comment
Share on other sites

Please start explaining what you mean when you say something doesn't work. It's a lot more helpful to someone trying to solve your problem.In the meantime, chew on this:1. Your document is allowed one body tag only. I suspect the onload handler defined in the second erases the first. Why have two functions anyway? Of if you want two, have each one called by a shell function.2. A Date object does not update itself. You create it, and it holds the same time forever. If you want to update the time, you need to create a new Date object every time your functions are called.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...