PDA

View Full Version : Stuck on linking variable


theonesage
02-20-2009, 06:05 PM
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>

Gjslick
03-01-2009, 08:25 PM
Actually, you wrote it correctly. That prototype function is fine. The problem is with the lines:


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."


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().