I did not have any considerations of month and day before, but always intended to put that in. Here is the "test code". I have it also in an actual page that I am putting together at
http://www.tdavisconsulting.com/kenerly. The test code works, but the actual page does not. I am not sure where to put the calcAge(). I have it on the DOB along with the date selector process (with onFocus). It works, but the date does not get put into the AGE field until the 2nd time.
Maybe I should use onBlur?
<script type="text/javascript">
function calcAge(returnAge) {
var dob_month;
var dob_day;
var dob_year;
var dob;
var message;
dob = document.form1.elements.dob.value;
var birthDay = dob.split("-");
dob_month = birthDay[0];
dob_day = birthDay[1];
dob_year = birthDay[2];
var time=new Date();
var lmonth=time.getMonth() + 1;
var date=time.getDate();
var year=time.getYear() + 1900;
returnAge = year - dob_year;
if (dob_month > lmonth) {
returnAge--;
}
if (dob_month == lmonth && dob_day > date) {
returnAge--;
}
document.form1.r_age.value=returnAge
return returnAge;
}
</script>
<body>
<form name="form1">
<p>Enter date of birth in format MM-DD-YYYY
<input id="dob" type="text" name="dob" value="">
</p>
<p id="itext">
Click the button below to calculate your age
</p>
<p>
<input type=button value='Click here to calculate your age' onclick="calcAge()">
</p>
<p>
Your age is: <input type="text" name="r_age" size="10" readonly style="border:0px solid black; background-color:transparent;">
</p>
</form>