Copy link to clipboard
Copied
I would like to calculate someone's age based upon whether a "permission" date is entered. If no permission date is entered in the "Permission" field, then the age is calculated on today's date and is displayed in the "Age" field (where I am writing the code). If a permission date is entered in the "Permission" field, then the age is calculated using the date entered in the "Permission" field and is displayed in the "Age" field. If not too much trouble, I would like the age to display as years & months (example: 11-10). Thank you in advance for help!!! Dave
Copy link to clipboard
Copied
Sorry for the delay!
I just added 2 lines at the end of the script for resetting the fields when the date of birth is empty, but that worked fine for me with the "Clear Form" button.
Please use this new file and let me know.
@+
Copy link to clipboard
Copied
Have you looked at all the other posts on calculating age? There must be hundreds.
Here's one that provides an age calc for the current date. It's a good place to start.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I discovered an issue with this automatic age calculation in a project i worked on recently:
- the form for a patient is to follow their progress over 3 years.
- The first visit works perfectly, age = today's date - date of birth
- Issue: every time the physician/secretary opens the file, the age is recalculated. Which is correct as per formula, but then we lose the actual age of each visit.
Copy link to clipboard
Copied
You need to move the code to the validation script of the DOB field, then. That way it will only update once that field's value is changed.
Copy link to clipboard
Copied
I have looked at many of the available posts. I do not have enough knowledge about code to piece things together from different posts so they will work for my project. For now, instead of leaving the "Permission" field blank, I will just enter "today's date" into "Permission" field until I have permission to evaluate the child, then change the date in the "Permission" field to the date permission was granted. Regarding displaying age in years and months: For now, I will have the "Age" field just display in years (11) instead of years & months (11-10). Simple and less automated will be better until I have time to learn more about code. 🙂
Thanks for your suggestion...
Copy link to clipboard
Copied
I have looked at many of the available posts. I do not have enough knowledge about code to piece things together from different posts so they will work for my project. For now, instead of leaving the "Permission" field blank, I will just enter "today's date" into "Permission" field until I have permission to evaluate the child, then change the date in the "Permission" field to the date permission was granted. Regarding displaying age in years and months: For now, I will have the "Age" field just display in years (11) instead of years & months (11-10). Simple and less automated will be better until I have time to learn more about code.
Thanks for your suggestion...
Copy link to clipboard
Copied
Here is the example from a previous one I did some times ago.
I hope it will help you!
@+
Copy link to clipboard
Copied
You example seems to be doing what I want; however, I cannot find where you have the code written to do the tasks? I am opening the document and going to "Prepare Form". Then I opened "age" and looked under "Calculate" and "Validate", but I don't see any code... and yet it works 🙂 Where is everything hidden? Thanks!
Copy link to clipboard
Copied
There is a function defined in document-level of my file:
and a run JavaScript on Blur action for both birthday and permission fields
@+
Copy link to clipboard
Copied
I do see java scripting of some sort when I right click on the "page". It may be important to point out that there are 40 students per page where these calculations are taking place.
Copy link to clipboard
Copied
As you have 40 studients, you certainly have fields with indices, so the script will be a bit different!
Could you share a file and I'll show you how do that...
@+
Copy link to clipboard
Copied
Of course I would be happy to share the form 🙂
Thank you for the help you have provided so far!!!
Copy link to clipboard
Copied
Hi,
Here is my copy!
I hope you'll understant what I did... else let me know.
@+
Copy link to clipboard
Copied
WOW!!! Everything works great! You wanted me to let you know if I understood what you did... I looked at the Java scripting and understood bits and pieces, no clue about indices... guess I will need to invest time into a class if I do much more with this type of form 🙂
Thank you so much for the help you gave me! I hope the holidays are great to you!!!
Dave
Copy link to clipboard
Copied
I did run into 1 small issue. Even when I delete/clear both the permission date and the date of birth, the "Student Age" and "Less than 12" fields retain the results from when previously calculated? I can certainly live with this small issue by waiting until I enter another student's information in the same place, but if there is a quick fix, that would be better? Thanks again!
Copy link to clipboard
Copied
Sorry for the delay!
I just added 2 lines at the end of the script for resetting the fields when the date of birth is empty, but that worked fine for me with the "Clear Form" button.
Please use this new file and let me know.
@+
Copy link to clipboard
Copied
This one works perfectly!!! Thank you again so much for your tremendous help! Happy Holidays to you and yours!!! Dave

