By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,689 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,689 IT Pros & Developers. It's quick & easy.

Trouble with Digital Clock showing in Form Text box.

P: 1
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.  
Oct 16 '09 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
a) there’s no content to apply the result to (not yet loaded)
b) line 13/17: this refers to window …
Oct 16 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.