I am trying to show an alert when someone selects a date in the past:
jQuery('#date').datepicker().change(evt => {
var selectedDate = jQuery('#date').datepicker('getDate');
var theSelectedDate = selectedDate.setHours(0,0,0,0);
var now = new Date();
var theNow = now.setHours(0,0,0,0);
if (theSelectedDate > theNow) {
// Date in in the future, all good
} else {
alert("Selected date is in the past");
}
});
..and the date field...
<input type="date" id="date" name="date" />
The problem is that regardless of what date I chose with the date picker, the alert is always 'Selected date is in the past' on mobile devices.
What the heck am I doing wrong?