| <SCRIPT>
/* checks to see which radio
button in the form the user has checked. If the document's form element
is checked, then it should return a true result, otherwise returns false
*/
function showMilitaryTime()
{ |
/* since the
radio buttons are an array, we have to use array notation in order
to refer to a particular radio button */
if (document.theForm.showMilitary[0].checked)
{ |
|
return true; |
| } |
| return false; |
| } |
// Display the time either as
Military Time or as the "normal" time
| function showTheHours(theHour)
{ |
| if (showMilitaryTime()
|| (theHour > 0 && theHour < 13)) { |
|
return (theHour); |
| } |
| if (theHour == 0) { |
|
return (12); |
| } |
| return (theHour -
12); |
| } |
// This function pads the output
with :0 if the time (secs & mins) < 10
| function showZeroFilled(inValue)
{ |
| if (inValue > 9) { |
|
return ":" + inValue; |
| } |
| return ":0"
+ inValue; |
| } |
// add AM or PM to 12 - hour
time, if showMilitaryTime is true, move on
| function showAmPm()
{ |
| if (showMilitaryTime())
{ |
|
return (""); |
| } |
| if (now.getHours()
< 12) { |
|
return (" am"); |
| } |
| return ("
pm"); |
| } |
// the Main Function - setTimeout()
tells the display to update every second
| function showTheTime()
{ |
| now = new Date(); |
document.theForm.showTime.value
=
showTheHours(now.getHours())
+
showZeroFilled(now.getMinutes())
+
showZeroFilled(now.getSeconds())
+
showAmPm(); |
| setTimeout("showTheTime()",
1000); |
| } |
</SCRIPT>
showTheTime() gets loaded after
the document is loaded with the onLoad
<BODY onLoad="showTheTime();">
| <FORM NAME="theForm"> |
| <INPUT
TYPE="TEXT"
NAME="showTime"> |
| Display Military Time? |
the radio buttons act as an array in this case,
with the first radio button being checked,
an array in this case means that when you check one of the buttons
the other one automatically gets unchecked
<INPUT
TYPE="RADIO"
NAME="showMilitary"
CHECKED>Yes |
| <INPUT
TYPE="RADIO"
NAME="showMilitary">No |
| </FORM> |
|