Hi there, Ive got the following problem with a code ive come across.
Code:
<script language="javascript">
function checkAge()
{
/* the minumum age you want to allow in */
var min_age = 16;
/* change "age_form" to whatever your form has for a name="..." */
var year = parseInt(document.forms["age_form"]["year"].value);
var month = parseInt(document.forms["age_form"]["month"].value) - 1;
var day = parseInt(document.forms["age_form"]["day"].value);
var theirDate = new Date((year + min_age), month, day);
var today = new Date;
if ( (today.getTime() - theirDate.getTime()) < 0) {
alert("Youre too young!");
return false;
}
else {
return true;
}
}
</script>
This code above works, and when submitted the form, it checks the age for the minimum of 16. As you can see.
Ive got a problem that it doesnt look at the days / month given.
Default the list is set at a value of 00.
I would like to add some additional JS code to check if the day and month have been given.
If not given. An alert box popup with a message will be displayed.
How would be that be achieved? Any advice is more than welcome since im a JS noob. Thanks!