@davidcholleyauthorMar 11.2003 — #I was having problems adapting the original code referenced, however I was able to sort out the problems. I'm not happy the I don't fully understand the logic, however I have verified that the function does return the correct number of days across non-leap & leap years.
@davidcholleyauthorMar 11.2003 — #Actually I just got a better picture of how the code works...
The option list referenced uses the actual month ordinal positions instead of the JavaScript ordinal positions. (1-12 versus 0-11).
The startDate value is actually the first day of the month that follows the selected month. Once the DATE object is created, the total number of milliseconds in a day (86400000)is subtracted from the date to obtain the day prior to the first day of the month. Then the getDate() function return the day of the month which happens to represent the number of days in the month.
@gil_davisMar 11.2003 — #You should try December. I believe your routine will fail, because it is not considering a year wrap. Here is a snip of a routine I use to calculate days in a month (among other things): var _year = val.year.value; var _first = new Date(val.year.value, val.month.selectedIndex, 1); var _month = val.month.options[val.month.selectedIndex].text; var _title = _month + ", " + _year; var _start = _first.getDay(); var _nmo = (val.month.selectedIndex + 1) % 12; var _nyr = (_nmo == 0) ? Number(_year) + 1 : Number(_year); var _end = new Date(_nyr, _nmo, 1); var _mlen = Math.round((_end - _first) / 86400000);To see the code at work:
I was having problems getting the calendar to automatically load to the current month due to another script on the page (the onLoad event for the body tag would not fire) which is why the calendar visiblity changes. I'm about to shift the validation to server-side due to the amount of code on the page so I should be able show the calendar when the page loads.