John Stockton

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJohn Stockton
ToMe
SubjectYour page ... validmonth.html
Date25 April 2007 16:59
Your page http://www.howtocreate.co.uk/jslibs/htmlhigh/validmonth.html
contains
       function dateChange( d, m, y )
including
       //find the number of days in that month

For the month Y (>0) M (1-12),
        DM = new Date(Y, M, 0).getDate()
does that more briefly.

        DM = new Date(Date.UTC(Y, M, 0)).getUTCDate()
should be quicker, but Firefox 2.0.0.3 Date.UTC treats D<1 as D=1.

Your code determines whether the year is Leap even is the month is not
February.
  suggested pseudo-code :    DM = (month==2 ? 28+isLeap(Y) : look-up)

You have something similar in page calendarpopup.html, function
doReDraw(sX,sY) .


That page has
function MWJ_dropMonth() { if( curDate.getMonth() ) { curDate.setMonth(
curDate.getMonth() - 1 ); } else { curDate.setMonth(11);
curDate.setYear( curDate.getTheYear() - 1 ); } doReDraw(); }

In compliant systems, setMonth(getMonth()-1) should work for all months.


For other date code, see sig.

It's a good idea to read the newsgroup [...] and its FAQ.  See below.

[Ed. no thanks - spammy self promotion links are not welcome]

John Stockton
FromMe
ToJohn Stockton
SubjectRe: Your page ... validmonth.html
Date1 May 2007 09:51
John,

> Your page contains

Yes, these are old scripts, so they use things that also work in older
browsers. Since they continue to work, I see no reason to change them in a
way that locks out older browsers. Your code, for example, fails in Netscape
4, and probably some others (I have not tested your code in all of the
browsers that were around when I wrote the scripts). Not too important right
now, but it was when I wrote the scripts.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.