I am using the onSelect
event in order to set the minimum value of the EndDate
equal to the value set as a StartDate
. I have the same code in several pages but in one of them it does not work. If I select a value in the StartDate
, datepicker does not show when I go in the EndDate
field. The pages are loaded and handled with ajax.
My Code is as follows:
$(document).ready(function() {
$("#strStartDate").datepicker({
dateFormat: 'dd/mm/yy',
constrainInput: true,
firstDay: 1,
hideIfNoPrevNext: true,
onSelect: function(){
$("#strEndDate").datepicker( "option", "minDate", $("#strStartDate").val());
}
});
$("#strEndDate").datepicker({
dateFormat: 'dd/mm/yy',
constrainInput: true,
firstDay: 1,
hideIfNoPrevNext: true
});
});
Any help is much appreciated. Thank you in advance.
Using the ideas behind your comments I manage to do almost the thing I want
$("#strStartDate").datepicker({
dateFormat: 'dd/mm/yy',
constrainInput: true,
firstDay: 1,
hideIfNoPrevNext: true,
});
$("#strEndDate").datepicker({
dateFormat: 'dd/mm/yy',
constrainInput: true,
firstDay: 1,
hideIfNoPrevNext: true,
beforeShow: function (input, inst) {
inst.settings.minDate = $("#strStartDate").val();
}
});
The above code restricts user from putting an end date smaller than the start date however if there was already a value in end date, and you change the start date to a value bigger than the end date it should set the end date equal to the start date. This is what I was trying to do with the code below in my early code
onSelect: function(){
$("#strEndDate").datepicker( "option", "minDate", $("#strStartDate").val());
}
Any idea how to do this using the instance and not initialize again?