Page 1 of 1

Realtime Click without using a form field

Posted: Fri Aug 09, 2002 3:35 pm
by Takuma
Hi, Hope this helps some poeple around here :D

This script uses DOM so it only works with NS6+, IE5+, Mozilla 1.0.

Code: Select all

function startTime(id)
	{
	  var currentTime = new Date();
	  var hr = currentTime.getHours();
	  var mn = currentTime.getMinutes();
	  var sc = currentTime.getSeconds();
	  hr = eval(hr);
	  mn = eval(mn);
	  sc = eval(sc);
	  if(hr < 10)
	  &#123;
	    hr = "0" + hr;
      &#125;
	  if(mn < 10)
	  &#123;
	    mn = "0" + mn;
	  &#125;
	  if(sc < 10)
	  &#123;
	    sc = "0" + sc;
	  &#125;
	  if(document.getElementById)
	  &#123;
	    document.getElementById(id).childNodes&#1111;0].nodeValue = " - " + hr + ":" +  mn + ":" + sc;
	  &#125;
	  setTimeout("startTime('basicTime')",500);
	&#125;
Add the following code to the BODY tag.

Code: Select all

onload="startTime('basicTime');"
And also where you want the clock to be...

Code: Select all

<span id="basicTime">&nbsp;</span>
That's it!!!!