<input type="date" name="bday" id="biday" required>
var startDate = Date(document.getElementByID('biday').value);
var today = new Date();
if (startDate > today) {
alert("The first date is after the second date!");
There are number of errors on your code like getElementByID
should be getElementById
and you are not taking the value
from input and so on. Check below snippet for reference.
function checkDate() {
var startDate = new Date(document.getElementById('biday').value);
var today = new Date();
if (startDate.getTime() > today.getTime()) {
alert("The first date is after the second date!");
}
}
<input type="date" name="bday" id="biday" required>
<input type="submit" value="check" onclick="checkDate()">