I have 2 datepickers on a page. Users are expected to enter 2 dates somewhat close to one another. However, if a user skips 6 months ahead, their intuition tells them that when they click the 2nd datepicker, it will also already be in that same month.
I need to set the defaultDate of the second datepicker, to the date selected in the first datepicker.
$("#from").datepicker({
defaultDate: new Date(),
minDate: new Date(),
onSelect: function(dateStr)
{
$("#to").val(dateStr);
$("#to").datepicker("option",{ minDate: new Date(dateStr)})
}
});
$('#to').datepicker({
defaultDate: new Date(),
onSelect: function(dateStr) {
toDate = new Date(dateStr);
fromDate = ConvertDateToShortDateString(fromDate);
toDate = ConvertDateToShortDateString(toDate);
}
});
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input id="from">
<input id="to">
But it fails to run. In fact it fails to initialise the datepickers at all.. And I'm not sure why. Just having them as normal datepickers of course works fine.
Does anyone have any other methods of achieving my goal?