User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 397,579 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,368 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 924 | Replies: 2 | Solved
Join Date: Feb 2007
Posts: 56
Reputation: adaykin is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
adaykin adaykin is offline Offline
Junior Poster in Training

Difficulty with forms

  #1  
Nov 23rd, 2007
Hello, I am getting an error message saying clock is undefined, I am not sure why, here is my code:

  1. <script type ="text/javascript">
  2. var theDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  3. var theMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  4. var birthYear = 1960;
  5. var birthDay = 1;
  6. var birthMonth = 1;
  7. var retirementYear;
  8. var retirementAge = 65;
  9. var timerId;
  10. var firstDate = new Date();
  11. var lastDate = new Date();
  12. var minutes = 1000 * 60;
  13. var hours = minutes * 60;
  14. var days = hours * 24;
  15. var years = days * 365;
  16.  
  17. function startClock()
  18. {
  19. birthYear = prompt("Type the 4-digit year of your birth.");
  20. birthMonth = prompt("What month? (1-12)");
  21. birthDay = prompt("What day? (1-31)");
  22. retirementAge = prompt("At what age to you plan to retire?");
  23. retirementYear = birthYear + retirementAge;
  24. firstDate = new Date("birthYear", "birthMonth", "birthDay");
  25. lastDate = new Date("retirementYear", "birthMonth", "birthDay");
  26. timerId = setInterval("showTime()", 1);
  27. }
  28.  
  29. function stopClock()
  30. {
  31. clearInterval(timerId);
  32. }
  33.  
  34. function showTime()
  35. {
  36. var now = new Date();
  37. var seconds = ((now.getTime() + (retirementAge * 31556926000)) - now.getTime()) / 1000;
  38. var birthDateDisplay = "" + theDays[now.getDay()] + "," + birthDay + " " + theMonths[birthMonth] + ", " + birthYear;
  39. var retirementDisplay = "" + theDays[now.getDay()] + "," + birthDay + " " + theMonths[birthMonth] + ", " + (birthYear + retirementAge);
  40. clock.txtSecondsFace.value = seconds;
  41. clock.txtMinutesFace.value = seconds / 60;
  42. clock.txtHoursFace.value = (seconds / 60) / 60;
  43. clock.txtDaysFace.value = (seconds / 60 / 60) / 24;
  44. clock.txtYearsFace.value = (seconds / 60 / 60 / 24) / 365;
  45. clock.txtWorkDays.value = retirementForm.txtYearsFace.value * .65;
  46. clock.txtFunDays.value = retirementForm.txtYearsFace.value * .35;
  47. clock.txtBirthDate.value = birthDateDisplay;
  48. clock.txtRetirementDate.value = retirementDisplay;
  49. }
  50.  
  51. </script>
  52.  
  53.  
  54. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  55. <title>Retirement</title>
  56. </head>
  57.  
  58. <body>
  59.  
  60. <h1>Retirement Countdown</h1>
  61. <br />
  62. <form name = "clock" action = "">
  63. <p>
  64. Click the Start Clock button to begin:
  65. <input name = "btnStartClock" value = "Start Clock" type = "button" onclick = "startClock()" />
  66. <input name = "btnStopClock" value = "Stop Clock" type = "button" onclick = "stopClock()" />
  67. </p>
  68. <p>
  69. Birth Date:
  70. <input name = "txtBirthDate" type = "text" />
  71. </p>
  72. <p>
  73. Retirement Date:
  74. <input name = "txtRetirementDate" type = "text" />
  75. </p>
  76. <p>
  77. <h3>Countdown to Retirement</h3>
  78. </p>
  79. <p>
  80. Seconds:
  81. <input name = "txtSecondsFace" type = "text" />
  82. Minutes:
  83. <input name = "txtMinutesFace" type = "text" />
  84. </p>
  85. <p>
  86. Hours:
  87. <input name = "txtHoursFace" type = "text" />
  88. Days:
  89. <input name = "txtDaysFace" type = "text" />
  90. Years:
  91. <input name = "txtYearsFace" type = "text" />
  92. </p>
  93. <p>
  94. <h3>Work Days Versus Fun Days</h3>
  95. </p>
  96. <p>
  97. A typical full time employee works 65 days out of every 100 days.
  98. </p>
  99. <p>
  100. Work days left:
  101. <input name = "txtWorkDays" type = "text" />
  102. Fun days before retirement:
  103. <input name = "txtFunDays" type = "text" />
  104. </p>
  105. </form>
  106. <p>
  107. <h2>Now that is something to think about!</h2>
  108. </p>
My Website <-- check out my site!
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:55 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC