0

i'm quite newbie to javascript. I'm struggling to create a small code in order to my datepicker only show/allow to be selectable the months July, August and September.

I'm using this code right now:

<script type='text/javascript'>
jQuery.noConflict();
  jQuery(document).ready(function($) {
$( "#input_7_13" ).datepicker({  dateFormat: 'dd/mm/yy',
       minDate: 1, onChangeMonthYear: function(year, month, inst) {
        if(month<5){
            year = year-1;
             $( this ).datepicker( "setDate" , new Date(year, 8, 1) )
             $( this ).datepicker("refresh");
        }
        if(month>9){
            year = year+1;
             $( this ).datepicker( "setDate" , new Date(year, 6, 1) )
             $( this ).datepicker("refresh");
        }
    }
});
});
</script>

So, if the month is lower than 5 (June) it takes a year and assumes the month 8 (September). If the month is greater than 89(October) it adds a year and assumes the month 9 (July).

This is working while going foward. If i try to go backwards, it will loop between July and May ...

1 Answers1

0

You can use this, but you'll need to modify the dates to match your specs.

Jquery:

 $('#selector').datepicker({
        //Set default date to: 2013-10-01
        defaultDate: new Date(2013, 9, 1),
        onChangeMonthYear: function(year, month, inst) {
                //0 based index on the months, from what I remember.
                if(month<4){
                    year = year-1;
                     $( this ).datepicker( "setDate" , new Date(year, 9, 1) )
                     $( this ).datepicker("refresh");
                }

                if(month>9){
                    year = year+1;
                     $( this ).datepicker( "setDate" , new Date(year, 4, 1) )
                     $( this ).datepicker("refresh");
                }

        }
});
Philip G
  • 4,098
  • 2
  • 22
  • 41