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

Month Date problem

P: n/a
Jim
I have been using the javascript below on a web page since last August to
show the "Site updated" month
minus a month, which has been very successful, but January is showing a
"undefined 2004" message.
Help much appreciated
Jim
var m=new Array(13);var n=new Date()

m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated
March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated
June";
m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
September";m[10]="Site updated October";m[11]="Site updated
November";m[12]="Site updated December"
document.write(m[n.getMonth()+0]+" "+n.getFullYear())
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
As of JDK version 1.1, replaced by Calendar.get(Calendar.MONTH).

"Jim" <ji*@internet.com> wrote in message
news:3f***********************@news.dial.pipex.com ...
I have been using the javascript below on a web page since last August to
show the "Site updated" month
minus a month, which has been very successful, but January is showing a
"undefined 2004" message.
Help much appreciated
Jim
var m=new Array(13);var n=new Date()

m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated June";
m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
September";m[10]="Site updated October";m[11]="Site updated
November";m[12]="Site updated December"
document.write(m[n.getMonth()+0]+" "+n.getFullYear())

Jul 17 '05 #2

P: n/a
It was caused when you invoked n.getMonth for January and got a
returned number 0, which means January. Then you saw a word
'undefined' extracted from an unassociated element m[0].

To solve the problem, just write as follow,

m[n.getMonth() - 1]

"Jim" <ji*@internet.com> wrote in message news:<3f***********************@news.dial.pipex.co m>...
I have been using the javascript below on a web page since last August to
show the "Site updated" month
minus a month, which has been very successful, but January is showing a
"undefined 2004" message.
Help much appreciated
Jim
var m=new Array(13);var n=new Date()

m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated
March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated
June";
m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
September";m[10]="Site updated October";m[11]="Site updated
November";m[12]="Site updated December"
document.write(m[n.getMonth()+0]+" "+n.getFullYear())

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.