home *** CD-ROM | disk | FTP | other *** search
/ Web Designer 98 (Professional) / WebDesigner 1.0.iso / tutorials / tutorial / clock.txt < prev    next >
Encoding:
Text File  |  1997-06-15  |  1.2 KB  |  44 lines

  1. <script language="JavaScript">
  2. <!-- Hide the script from old browsers --
  3.  
  4. // Michael P. Scholtis (mpscho@planetx.bloomu.edu)
  5. // All rights reserved.  December 22, 1995
  6. // You may use this JavaScript example as you see fit, as long as the
  7. // information within this comment above is included in your script.
  8.   
  9.  
  10. var timerID = null;
  11. var timerRunning = false;
  12. var id,pause=0,position=0;
  13.  
  14. function stopclock (){
  15.         if(timerRunning)
  16.                 clearTimeout(timerID);
  17.         timerRunning = false;
  18. }
  19.  
  20. function showtime () {
  21.         var now = new Date();
  22.         var hours = now.getHours();
  23.         var minutes = now.getMinutes();
  24.         var seconds = now.getSeconds()
  25.         var timeValue = "" + ((hours >12) ? hours -12 :hours)
  26.         timeValue += ((minutes < 10) ? ":0" : ":") + minutes
  27.         timeValue += ((seconds < 10) ? ":0" : ":") + seconds
  28.         timeValue += (hours >= 12) ? " P.M." : " A.M."
  29.         document.clock.face.value = timeValue;
  30.         timerID = setTimeout("showtime()",1000);
  31.         timerRunning = true;
  32. }
  33.  
  34. function startclock () {
  35.         stopclock();
  36.         showtime();
  37. }
  38. // --End Hiding Here -->
  39. </script>
  40. <body onLoad="startclock()">
  41. <form name="clock" onSubmit="0">
  42. <input type="text" name="face" size=13 value="">
  43. </form>
  44.