Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2009, 06:05 PM   PM User | #1
theonesage
New to the CF scene

 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
theonesage is an unknown quantity at this point
Unhappy Stuck on linking variable

I am trying to link the variable (m) to the getMonth() function below it, or replace it whatever I need to do. I want the month to be displayed in words instead of numbers. Thanks if you can help.



<script language="javascript">

Date.prototype.getMonthName = function()
{
var m = ['January','February','March','April','May','June','July',
'August','September','October','November','December'];
return m[this.getMonth()];
}

var clockID = 0;
function UpdateClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
var tDate = new Date();
document.theClock.theTime.value = ""
+ tDate.getMonth() + " "
+ tDate.getDay() + ", "
+ tDate.getYear() + " "
+ tDate.getHours() + ":"
+ tDate.getMinutes() + ":"
+ tDate.getSeconds();

clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
clockID = setTimeout("UpdateClock()", 500);
}
function KillClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
}

</script>

<form name="theClock" class="myform">
<input type="text" name="theTime" size="25" />
</form>
theonesage is offline   Reply With Quote
Old 03-01-2009, 08:25 PM   PM User | #2
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Actually, you wrote it correctly. That prototype function is fine. The problem is with the lines:

Code:
   var tDate = new Date();
   document.theClock.theTime.value = ""  
   + tDate.getMonth() + " "
   + tDate.getDay() + ", "
   + tDate.getYear() + "    "
   + tDate.getHours() + ":" 
   + tDate.getMinutes() + ":" 
   + tDate.getSeconds();
These need to have the plus sign at the end of the lines, so that the javascript interpreter won't think that you just left out a semicolon and treat it as an "end line."

Code:
var tDate = new Date();
document.theClock.theTime.value = tDate.getMonthName() + " " + 
   tDate.getDate() + ", " + 
   tDate.getFullYear() + " " + 
   tDate.getHours() + ":" + 
   tDate.getMinutes() + ":"    + 
   tDate.getSeconds();
Also, I replaced getDay() with getDate() (as getDay gets the day of the week, 0-6), and getYear() with getFullYear().
Gjslick is offline   Reply With Quote
Reply

Bookmarks

Tags
date, javascript, linking, time

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:50 PM.


Advertisement
Log in to turn off these ads.