I've encountered a challenge trying to populate a field in an interactive PDF form. I am utilizing JavaScript to calculate the current age of a client by subtracting two date fields (DateToday and ClientDOB) already present in the form, and then aiming to have it display in a "ClientAge" field. The DateToday field is set to auto-populate when the form is opened. My goal is for the ClientAge field to populate once the user selects a value for ClientDOB.
My desired calculation is as follows, which seems straightforward:
DateToday - ClientDOB = ClientAge
Below is the code I'm using:
var DateToday_ = Date2Num(DateToday.formattedValue, "MM/DD/YYYY")
var ClientDOB_ = Date2Num(ClientDOB.formattedValue, "MM/DD/YYYY")
var diff = DateToday_ - ClientDOB_
ClientAge.value = Floor(diff / 365.25)
I'm puzzled as to why the ClientAge field isn't populating after selecting ClientDOB. Any insights or assistance would be greatly appreciated. Thank you.