Calculating age in years from DOB and document date from separate fields for month, day and year
Full disclaimer: I know NOTHING about Javascript. I've copied and pasted the scripts of other geniuses and have tried to understand the logic behind their scripts but just can't seem to grasp it. Anyway, I have an age field on a form into which I want the age in years automatically calculated from the DOB and the document's date based on separate fields for month, day and year. Until now, I could only find the following script that calculates based on the current date. I don't want the current date but, instead, the date typed into three separate date fields for Month / Day / Year (fields are "MM", "DD" and "Year"). The current script is below:
var dob = util.scand("mm/dd/yyyy", this.getField("Date of Birth").valueAsString);
if (dob != null) {
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
var m = today.getMonth() - dob.getMonth();
if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) {
age--;
}
event.value = age;
}
else {
event.value = "";
}
if(event.value == 0)
event.value = "";
