JQuery / datepicker: set max date in terms of years

In my form, I would like the datepicker initialized to today to be set to ten years from today. This is what I tried looking on stackoverflow:

jQuery('#datepicker').datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    yearRange: "-80:+0",
    dateFormat: 'dd-mm-yy',
    maxDate: "+10y"
});

jQuery('#datepicker').datepicker().datepicker("setDate", new Date());

      

or

jQuery('#datepicker').datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    yearRange: "-80:+0",
    dateFormat: 'dd-mm-yy'
});

var todayDate = new Date();
jQuery('#datepicker').datepicker().datepicker("setDate", todayDate);
jQuery('#datepicker').datepicker().datepicker( "option", "maxDate", new Date(todayDate.getFullYear()+10, todayDate.getMonth(), todayDate.getDate()));

      

and obviously both didn't work. I think I am making a stupid mistake by causing my lack of experience with jQuery. Any help?

+3


source to share


1 answer


Change this

yearRange: "-80:+0",

      



to

yearRange: "-80:+10",

      

+6


source







All Articles