Connecting Tech Pros Worldwide Help | Site Map

Trouble with Digital Clock showing in Form Text box.

Newbie
 
Join Date: Sep 2009
Location: Raleigh, NC
Posts: 1
#1: Oct 16 '09
Hello, I have created the below script; however, it's not showing in the box like it should... Help please!! I am running out of time to submit this assignment!

Thanks in advance!!



Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. /* <! [CDATA[ */
  3.  
  4. function display() {
  5.     var Today = new Date();
  6.     var hours = Today.getHours();
  7.     var min = Today.getMinutes();
  8.     var sec = Today.getSeconds();
  9.     var Time = ((hours > 12) ? hours - 12 :(hours == 0) ? 12 :hours);
  10.     Time += ((min < 10) ? ":0" : ":") + min;
  11.     Time += ((sec < 10) ? ":0" : ":") + sec;
  12.     Time += (hours >= 12) ? " PM" : " AM";
  13.     this.clockForm.clock.value = Time;
  14.     setInterval("display()",1000);
  15.     } 
  16.  
  17.     display(); 
  18.  
  19.  
  20. /* ]]> */
  21. </script>
  22.  
  23. <body>
  24.  
  25. <h1>What time is it?</h1>
  26.  
  27. <form name = "clockForm">
  28.   <input type="text" name="clock" />
  29. </form>
  30.  
  31. </body>
  32.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,624
#2: Oct 16 '09

re: Trouble with Digital Clock showing in Form Text box.


a) there’s no content to apply the result to (not yet loaded)
b) line 13/17: this refers to window …
Reply