I need to change minDate of jQuery's datepicker each the time value of #position or #type changes. Currently the value for the minDate changes only the first time either #position or #type evokes the .change() method.
I am currently using the code below:
$("#position, #type").change(function(){
var pos = $("#position").val();
var type = $("#type").val();
var url = "getdate/"+type+"/"+pos;
$.get(url, function(msg){
$('.date1').datepicker({
MinDate: msg
});
});
})
That's because you are re-initiating the
.datepickermethod everytime there is a.change()event.Instead of this, initiate the
datepickeronce on the class.date1and then changeMinDateas follows:So this would yield:
Alternatively, you can also destroy the
.datepickerobject as follows:And then recreate the object as in your own code. So combined this would yield:
Also, please consult this question and answer:
jQuery DatePicker -- Changing minDate and maxDate on the fly