JavaScript Date Range

Here is code which restricts user to pick date in range. It is not about the normal "From:" and "To:" dates. The script is about the months you allow to pick in 12 months. The below code show the date from previous months of the current year to the current month of last year. So, the below range code will show the months from Aug, 2010 to Sept 2009 as current month is Sept of 2010. If you want to change the range then change the number given in JavaScript code. Hint is given as comment there.


<script type="text/javascript>
	var selMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var daysInMonthArr = [31,28,31,30,31,30,31,31,30,31,30,31];
	var currYear  = new Date().getFullYear();
	var currMonth = new Date().getMonth();
	var currDate  = new Date().getDate();
	var k=0;
	var rangeArr = new Array();
        // Change the number (11) to change the range
	for (var c=currMonth; c <=(currMonth+11) ; c++ )
	{
		if (c < 12)
		{
			rangeArr[k++] = selMonth[c] + ', '  +  (currYear-1)/1;
		}
		else
		{
			var j = 0;
			j = c - 12;
			rangeArr[k++] = selMonth[j] + ', '  +  (currYear);
		}
	}
</script>

<select name="month_year">
	<option value="#">--month--</option>
		<script>
			for (var i=rangeArr.length-1; i >= 0 ; i-- )
			{
				document.write('<option value="' + rangeArr[i] + '">' + rangeArr[i] + '</option>');
			}
		</script>
</select>

Sample Output:
Aug, 2010
Jul, 2010
Jun, 2010
May, 2010
Apr, 2010
Mar, 2010
Feb, 2010
Jan, 2010
Dec, 2009
Nov, 2009
Oct, 2009
Sep, 2009

Comments are open for an year period. Please, write here on Facebook page.