Simple Clock
Last Updated: June 6, 1997
- Example
- Installation and Script Code
Example of the JavaScript Clock
Installation and Script Code
To install the JavaScript Simple Clock onto your Virtual Server, you will need
to include the following JavaScript code inside of the <head> element on
your HTML page:
<script Language="JavaScript">
<!--
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = " " + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
document.simpleclock.face.value=timeValue;
// you could replace the above with this
// and have a clock on the status bar:
//window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
// Make sure the clock is stopped
stopclock();
showtime();
}
//-->
</script>
Now that the JavaScript source code is included in your document,
you must include the onLoad="startclock()" in your
document's <body> tag. This will execute the JavaScript
when the document loads. You must also specify a place for the
clock to display. This is done using an <input> element
inside a form. For example:
<body ..... onLoad="startclock()">
.
.
.
<form name="simpleclock" onSubmit="0">
<input type=text size=13 name="face" value="">
</form>
If you are unfamiliar with JavaScript, or would like to
learn more about JavaScript,
the following URL is an excellent resource:
http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/
|