Help! I think I deleted Februrary!

I can’t bring February up using my Javascript. I am using the following code, which I got straight from a book, to list the months in an HTML form. The user would select the month (as well as a day and year) from the list, and a calculation would be performed (number of days, day of the week, etc). When I run the code, I get “Jan Mar Mar Apr May Jun Jul Aug Sep Oct Nov Dec”. NO FEB!!! In the book’s app, the user selects two dates and the script calculates the number of days between. I tried selecting the first Mar to see if it was just Feb misnamed, but the computer calculated it as the month of Mar, not Feb.

Did I do something to accidentally write over February on my computer and replace it with March? The only way I could have done so was through JavaScript, since that is all I do (well that and HTML/CSS). How do I fix this???

Here is the code in question:

	function writeMonthOptions()
			var theMonth;
			var monthCounter;
			var theDate = new Date();
			for (monthCounter = 0; monthCounter < 12; monthCounter++)
				theMonth = theDate.toString();
				theMonth = theMonth.substr(4, 3);
				document.write("<option value=" + theMonth + ">" + theMonth);

Thank you in advance for the help.

Your new Date() is probably December 31-
if you change only the month to February you are getting February 31, which is resolved to March 3 (it would be March 2 in 2012).

Set the starting date to the 1rst of the month, instead of whatever todays date may be.
var theDate = new Date(2011,0,1); //january 1,2011

It would actually need to be either 29th or 30th to get that result.

31st would give:

Jan Mar Mar May May Jul Jul Aug Oct Oct Dec Dec

Right you are, felgall.