I have follow jQuery UI Datepicker sample code
jQ
You can use the onSelect event and call setDate method:
$("#datepicker1, #datepicker2, #datepicker3, #datepicker4").datepicker();
$("#datepicker1").datepicker("option", "onSelect", function (dateText, inst) {
var date1 = $.datepicker.parseDate(inst.settings.dateFormat || $.datepicker._defaults.dateFormat, dateText, inst.settings);
var date2 = new Date(date1.getTime());
date2.setDate(date2.getDate() + 1);
$("#datepicker2").datepicker("setDate", date2);
var date3 = new Date(date1.getTime());
date3.setDate(date3.getDate() + 2);
$("#datepicker3").datepicker("setDate", date3);
var date4 = new Date(date1.getTime());
date4.setDate(date4.getDate() + 3);
$("#datepicker4").datepicker("setDate", date4);
});
Demo here
The onSelect
passes the date as a string so we convert it to JavaScript Date object for convenience, using the following jQuery UI datepicker utility function:
$.datepicker.parseDate( format, value[, settings] )
The expression:
inst.settings.dateFormat || $.datepicker._defaults.dateFormat
means use the dateFormat
value specified on the datepicker, if there is one; otherwise use the dateFormat
from datepicker defaults (which is "mm/dd/yy"
).