I have this code that I want to check if a date is in the past. I want to check it as soon as the date is entered, before form submission.
All you need to do is convert the string produced by the into a Date using the Date constructor
new Date("2014-06-12")
function checkDate() {
var selectedText = document.getElementById('datepicker').value;
var selectedDate = new Date(selectedText);
var now = new Date();
if (selectedDate < now) {
alert("Date must be in the future");
}
}