onsubmit return false still submitting form
HTML:
<!DOCTYPE html>
<head>
<script src = "Scripts/script.js"></script>
</head>
<body>
<form action = "http://posttestserver.com/post.php" method = "post" onsubmit = "return age()">
<label for = "dob">Date of Birth</label> <input class = "TextArea" type = "date" id = "dob" name = "dob" required/> <br/>
<p><span id = "invalid"> </span><br/></p>
<input id = "FormSubmit" class = "Buttons" type = "submit" value = "Submit"/>
</form>
</body>
Javascript:
function age()
{
var invalidStr = "You must be at least 18 to subscribe.";
var submitOK = true;
var dateOfBirth = document.getElementById("dob").value;
var dateOfBirthD = dateOfBirth.split("/")[0];
var dateOfBirthM = dateOfBirth.split("/")[1];
var dateOfBirthY = dateOfBirth.split("/")[2];
var currentDate = new Date();
if (dateOfBirthY > (currentDate.getFullYear() - 18))
{
document.getElementById("invalid").firstChild.nodeValue = invalidStr;
submitOK = false;
}
return submitOK;
}
PS: External Javascript is not a problem since I have other scripts running in the background which worked fine