I am currently adding validation to my date pickers and am having trouble setting the min date in the to date picker to be whatever was chosen in the from date picker. I.e if 12-3-15 is selected then the minimum date in the to date picker is 12-3-15. Here is the code I am using:
$("#from").datepicker({
defaultDate: new Date(),
minDate: new Date(),
onSelect: function(dateStr)
{
fromDate = new Date(dateStr);
}
});
$('#to').datepicker({
defaultDate: new Date(),
minDate: ("#from" + "1D"), (<- HERE)
onSelect: function(dateStr) {
toDate = new Date(dateStr);
// Converts date objects to appropriate strings
fromDate = ConvertDateToShortDateString(fromDate);
toDate = ConvertDateToShortDateString(toDate);
});
Does anybody know how I could achieve this?
Please check this working fiddle
JSFiddle
Use option
to set the minDate
to the second datepicker
$("#from").datepicker({
defaultDate: new Date(),
minDate: new Date(),
onSelect: function(dateStr)
{
$("#to").val(dateStr);
$("#to").datepicker("option",{ minDate: new Date(dateStr)})
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With