I'm new to javascript. I'm trying to create a page that has an input option for date of birth. Once the submit button is clicked, I want to verify that the person is not underage (above 18).
This is my HTML code
<form id="myForm" method="get" action="#">
<p>Date of birth: <input type="date" name="dob" value="MM-DD-YYYY" required></p>
<p><input type="submit" value="submit" onclick="return validate_date_of_birth()">
</form>
and this is my javascript function:
function validate_date_of_birth(){
var dob = document.forms["myForm"]["dob"].value;
var ageDifMs = Date.now() - dob.getTime();
return true;
}
I'm getting a problem with dob.getTime(). Note that I'm not really verifying the age in the above code. That would require an if loop to verify the age. I'm stuck at a point where the difference is not being calculated. I tried to check the values of Date.now() and dob.getTime() by using the alert() function in javascript. For dob.getTime(), the value it prints out is "undefined". What am I doing wrong?