var months = [
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"];
//for some odd reason year+5 is a possible infinite loop
function setDates( )
{
var year= (new Date()).getFullYear();
var i, option;
//alert( year );
for( i=year; i < year+5; ++i ) {
//jQuery has shortcut procedure for this
option = new Option( i, i );
$(option).innerHTML = i;
$('#delivYr').append(option);
}
for( i=0; i < months.length ; ++i ) {
option = new Option( months[i], i+1 );
$(option).innerHTML = months[i];
$( '#delivMo' ).append( option );
}
//could set selected month to current month
//enable it as soon as month is set
//$('#delivDy').prop( 'disabled', true );
updateDays( );
}
/** this updateDays is a lot cleaner
than the textbook version */
function updateDays( ) {
var month = $('#delivMo').find( ":selected" ).val();
var lastDay=31;
switch( parseInt(month) ) {
case 2: lastDay=28;
if( parseInt($('#delivYr').find(":selected").val())%4
=== 0 ) ++lastDay;
break;
/* April June September November */
case 4: case 6: case 9: case 11:
lastDay=30; break;
}
//alert( month + ", " + lastDay );
$('#delivDy').empty( );
for( var i = 1; i <= lastDay ; ++i ) {
option = new Option( i, i );
$(option).innerHTML = i;
$('#delivDy').append(option);
}
}
setDates();
$('#delivYr').change( updateDays );
$('#delivMo').change( updateDays );
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.