Andrei Chivu Andrei Chivu - 2 months ago 7
jQuery Question

JS how to dynamically populate a second date picker with minDate of the first one

How can I populate 2 date pickers? The second date picker has to have at least the value of first date picker.This is my code right now:

selector.dtmDlgLimitFrom.attr('readonly', true).datepicker({
changeMonth: true,
changeYear: true,
minDate: dateToday,
yearRange: "0:+100"
});
selector.dtmDlgLimtTo.attr('readonly', true).datepicker({
changeMonth: true,
changeYear: true,
minDate: selector.dtmDlgLimitFrom.datepicker("getDate"),
yearRange: "0:+100"
});

Answer

you can try following to set the min date of second date selector:

 minDate: $("#idoffirstdateselector").datepicker("getDate") });

e.g.

selector.dtmDlgLimtTo.attr('readonly', true).datepicker({
     changeMonth: true,
     changeYear: true,
     minDate: $("#idoffirstdateselector").datepicker("getDate") }),
     yearRange: "0:+100"
});

idoffirstdateselector is id of the first date selector.