Calculating age from DOB field in Acrobat
This is a followup to Calculating Age from DOB field in Acrobat but I'm opening a new question because every time I respond to an existing question in various techs support forums I get slammed. If opening a new question is the wrong thing to to here, I apologize.
Using Acrobat X, I am trying to use this code in a field named Age to calculate age from a field named DOB (I'm sorry but I don't see an editing button to format it as code):
event.value = "";
var dobValue = this.getField("DOB").value;
if (dobValue!="") {
var dob = util.scand("dd/mm/yyyy", dobValue);
var today = new Date();
// compute age in milliseconds
var age = today.getTime() - dob.getTime();
// convert age to years ( millsec in sec * sec in min * min in hrs * hrs in day * days in year)
// truncate to whole years and adjust for binary floating point error
event.value = Math.floor( age / (1000 * 60 * 60 * 24 * 365.2425) - 0.005);
}
The debugger throws the following errors. How can I fix these?
dob is null
11:AcroForm:Age:Calculate
TypeError: dob is null
11:AcroForm:Age:Calculate
The DOB field is formatted as Date m/d/yyyy, and there very definitely is a value entered in that field.
Thanks to all.
