JQuery DatePicker Update Date When Changing Month Or Year

I recently had a requirement to make the JQuery Datepicker change the date of my input as the month or year was scrolled. For example if I clicked the input field and the calendar was on 02/22/2014 and I then clicked the next month button then the input field should automatically update to 03/22/2014. This was needed for quicker entry.

I was able to add some simple code to the “onChangeMonthYear” event to accomplish this. See below.

$(“#datepicker”).datepicker({
onChangeMonthYear: function(year, month, inst){
var day = inst.selectedDay;
$(this).datepicker(‘setDate’, new Date(year, month – 1, day));
}
});

Leave a comment

Your email address will not be published. Required fields are marked *


4 × eight =