Auto-Fill a PDF Field Based on Age in Adobe Acrobat
Question details
Automatically populate one PDF form field based on the age entered in another field.
- Product
- PDF form fields
- Device & OS
- not provided
- Scenario
- A form needs to assign a result according to an age entered in a source field.
- Observed behavior
- The destination field should show a value determined by the source age range.
Identify the exact name of the field that holds the age and the destination field that should display the result. You need a PDF form editor that supports custom calculation scripts, such as Adobe Acrobat Pro.
Add a Custom Calculation Script to the Destination Field
Use this method to return 4 for ages 45–100, 0 for ages 1–44, and a blank result for other values.
Open the PDF in Adobe Acrobat Pro and select All tools > Prepare a form.
Double-click the age field and check its name on the General tab. Create or identify a separate text field for the calculated result.
Double-click the destination field, open the Calculate tab, select Custom calculation script, and click Edit. Enter this script, replacing AgeField with the exact source field name: var age = Number(this.getField("AgeField").value); if (age >= 45 && age <= 100) event.value = "4"; else if (age >= 1 && age <= 44) event.value = "0"; else event.value = "";
In Prepare a form, open More > Set field calculation order. If the age field is itself calculated, move it before the destination field, then save the PDF.
Exit form editing and enter ages such as 20, 45, and 101 in the age field. Confirm that the destination shows 0, 4, and blank, respectively.

Edit PDF Documents and Office Files with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files. Its format compatibility makes it easy to move existing documents into WPS; use a PDF editor that supports custom calculation scripts for the age-based automation described above.

Frequently Asked Questions
Where do I put the age calculation script?
In Adobe Acrobat Pro, open All tools > Prepare a form, double-click the destination field, and select Calculate > Custom calculation script > Edit.
What should I replace AgeField with?
Replace AgeField in the script with the exact name shown on the General tab of the source age field's properties. Keep the name inside quotation marks.
Why is the result blank for an age of 44.5?
The specified ranges end at 44 and begin again at 45, so 44.5 falls between them. Adjust the conditions in the custom calculation script if fractional ages should receive a result.
Will the calculation work in every PDF viewer?
No. The viewer must support and allow PDF form JavaScript. Test the saved form in the viewer your recipients will use.




