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

digital clock

P: 9
Hi: I am an retired school teacher who went back to school for the fun of it. my subjects were computer hardware. I am taking a course in javascript and it is about to get the better of me. I need some help with is this one. I got it to validate. But something is wrong with the logic maybe. It bombs out on object expected .
Please give me some input. thanks
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Digital Clock</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function curTime() {
var now = new date();
var day = now.GetDay();
var date = now.GetDate();
var year = now.GetFullYear();
var month = now.GetMonth();
var hours = now.GetHours() + 1;
var minutes = now.GetMinutes();
var seconds = now.GetSeconds();
var days = new Array();
days[0] = "Sunday"; days[1] = "Monday"; days[2] = "Tuesday";
days[3] = "Wednesday"; days[4] = "Thursday"; days[5] = "Friday";
days[6]="Saturday";
var display = days[day] + " " + month + "/" + date + "/"
+ year + " "+ hours + ":" + minutes + ":" + seconds;
document.forms[0].Readout.value = display;
}
var tick = setInterval("curTime()", 1000);
// STOP HIDING FROM INCOMPATIBLE BROWSERS --></script></head>
<body>
<form action="">
<p><input type="text" size="30" name="readout" /></p>
</form>
</body>
</html>
Nov 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: 22
I doubt this will solve the problem, but make sure the cases are matching. Your input name is "readout" but you're calling it as "Readout".
Nov 15 '06 #2

P: 22
Furthermore, I believe you'll have to call the function when the page is loaded, ie body onLoad="CurDate()"... sorry I can't actually play around with it right now but I think that would be needed....
Nov 15 '06 #3

Expert 100+
P: 1,892
Expand|Select|Wrap|Line Numbers
  1. <!-- Adjust the placement of the clock in the line below -->
  2. <span id="pendule"></span>
  3. <script language="javascript" type="text/javascript">
  4. <!--
  5. function clock() {
  6. var digital = new Date();
  7. var hours = digital.getHours();
  8. var minutes = digital.getMinutes();
  9. var seconds = digital.getSeconds();
  10. var year = digital.getFullYear();
  11. var day = digital.getDay();
  12.  
  13. var month = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec")
  14. var day = new Array ("Sun","Mon","Tues","Wed","Thurs","Fri","Sat")
  15. var amOrPm = "AM";
  16. if (hours > 11) amOrPm = "PM";
  17. if (hours > 12) hours = hours - 12;
  18. if (hours == 0) hours = 12;
  19. if (minutes <= 9) minutes = "0" + minutes;
  20. if (seconds <= 9) seconds = "0" + seconds;
  21. dispTime = day[digital.getDay()] + "." + " " + month[digital.getMonth()] + " " + digital.getDate() + "," + " " + year + " ";
  22. dispTime = dispTime + hours + ":" + minutes + ":" + seconds + " " + amOrPm;
  23. document.getElementById('pendule').innerHTML = dispTime;
  24. setTimeout("clock()", 1000);
  25. }
  26. window.onload=clock;
  27. // -->
  28. </script>
Nov 15 '06 #4

Expert 100+
P: 1,892
Sorry missed the Edit timeout. This is one I've used for quite some time if need be I can make yours work, but nosense re-inventing the wheel.


HTH,
Aric
Nov 15 '06 #5

Post your reply

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