Custom calculations in PDF forms: answered for the whole community
Calculation questions make up a large share of the traffic in the PDF Forms section of this community. Most of them are variations of the same core scenarios — the same situations, described in different ways, by different users, year after year. This post collects the most common ones and provides complete answers in one place. Every script here is ready to use. Adjust the field names to match your form, paste the script, and the calculation works.
Before you begin
How to add a calculation script to any field
- Open your PDF in Acrobat. Select All Tools → Prepare a Form to enter form editing mode. Create a text field for each input value and one for the result.
- Double-click the result field to open its Properties. Select the Calculate tab, then choose Custom calculation script and select Edit.
- Paste the script. Select Close, then save the PDF. Acrobat runs the calculation automatically whenever an input field changes.
- Field names are case-sensitive. If the script references
UnitPrice, your field must be named exactlyUnitPrice. A space, different capitalisation, or a typo will stop the calculation from working. For a full walkthrough, see Configure form field calculations in Acrobat on Adobe Help document.
1 Quantity × unit price, with a grand total across all rowsOrder forms, purchase requests, invoices | |||||||||
| This is the most frequently asked form calculation in the community. Users typically have quantity and price fields in multiple rows and need each row to calculate its own total, with all row totals added into a single grand total. Two scripts are needed. The first calculates each row's line total (quantity × price). The second, placed in the Grand Total field, sums all line totals. A loop handles any number of rows — just change one number. Field names to use:
Paste this script in Total_1 → Calculate. For each additional row, copy the same script and change Paste this script in GrandTotal → Calculate. Change Calculation order. If GrandTotal always shows zero, go to Prepare a Form → More → Set field calculation order and move all Total_N fields above GrandTotal in the list. GrandTotal must calculate last.
|
2 Tax amount and percentage of a subtotalInvoices, receipts, expense reports | ||||
| This is the most common source of incorrect results in community threads. Users apply the Percentage format category to a field and find their result is 100 times too large. The cause and the solution are both straightforward. Acrobat's Percentage format multiplies the stored value by 100 for display. A field showing "7%" is actually storing 0.07. To calculate tax correctly, format your tax fields as Number — not Percentage — and divide the rate by 100 in the script.
The user enters the rate as a plain number — for example, 7 for 7%. Paste this in TaxAmount → Calculate. Paste this in GrandTotal → Calculate. i Format TaxAmount and GrandTotal as Number in the field's Format tab. See Format form fields in Acrobat for full formatting options. |
3 Auto-fill today's date when the form is openedAll form types | |
| This question appears across every category in the community. Users want a date field that populates automatically without the person filling in the form having to type anything. A custom calculation script placed in the date field reads the system clock every time any field on the form is updated, keeping the date current. The display format is set using Field names to use:
Paste this in TodayDate → Calculate. The field's Format tab can be left as None — the script controls how the date appears. i. The date recalculates whenever any field on the form changes, not only when the form opens. If you need the date locked to the first open, use a document-level script instead. See Add and debug JavaScript in Acrobat for document-level scripting.
|
4 Checkboxes that each add a value to a running totalRegistration forms, event booking, service selection | |||||
| A common pattern in registration and booking forms — each checkbox represents an option with a fixed price, and a total field should reflect the sum of all selected options. Set each checkbox's Export Value (in Properties → Options) to its price. The calculation script then reads all checkboxes and adds up only the ones that are checked. Unchecked checkboxes return the string "Off", not zero — the script handles this correctly. Field names to use:
In each checkbox's Properties → Options, set the Export Value to its price (e.g. 500, 250, 750). Paste this in CBTotal → Calculate. Change i. An unchecked checkbox always returns the string
|
5 Dropdown selection that changes what gets calculatedConditional pricing, membership tiers, service types | |||||
| Users frequently need a result field to behave differently based on a dropdown choice — apply a multiplier if the answer is "Yes", show zero if it's "No", or apply different rates for different membership levels. An if/else statement in the calculation script reads the dropdown's current value and runs the appropriate calculation for each option. This pattern works for Yes/No choices, multi-tier pricing, discount types, or any selection that determines how the maths should work. Field names to use:
The string in the i. To handle more than two options, add |
6 Calculate age from a date of birth fieldMedical intake, HR, school enrolment, membership forms | |||||
| This question comes up regularly in medical, HR, and school form discussions. Users need the age to calculate from a DOB field and update automatically — including handling leap years and the boundary case where a birthday falls later in the year. The script calculates age in whole years, accounting for whether the person's birthday has occurred yet this calendar year. Using Field names to use:
Format DOB as Date (mm/dd/yyyy) in its Format tab. Paste this in Age → Calculate.
|
Quick reference
What each part of the script does
| this.getField("Name") Locates a field in the PDF by its exact name. | .value Reads the current contents of that field. | parseFloat(…) || 0 Converts the value to a number. Returns zero if the field is empty. |
| event.value = … Sets the result in the field that contains the script. | .toFixed(2) Rounds to 2 decimal places — suitable for currency and hours. | valueAsString Safer way to read date fields. Avoids a known Acrobat date conversion issue. |
Adobe Help document — read further
Official documentation for form calculations and scripting
- Configure form field calculations in Acrobat
Step-by-step guide to the three calculation methods — predefined, simplified field notation, and custom JavaScript. Covers calculation order. -
Manage form field properties in Acrobat
How to set field names, formats, tooltips, required fields, and calculated values -- the foundation for everything in this post. -
Format form fields in Acrobat
Covers Number, Percentage, Date, and Currency format options -- including why the Percentage category affects calculated values and how to handle it. -
Add and debug JavaScript in Acrobat
How to use the JavaScript Console and Debugger in Acrobat to test scripts, view errors, and troubleshoot calculations that aren't producing the expected result. -
Apply actions and scripts to PDFs
Broader reference for JavaScript actions in Acrobat — triggers, document-level scripts, and links to the full Acrobat JavaScript API Reference.
A note on JavaScript support in Acrobat forms
The calculation scripts in this post use Acrobat JavaScript — Adobe's implementation of JavaScript for PDF forms. Before using them, there are a few things worth knowing about where and how they work.
What is required to author a form with these scripts Writing custom calculation scripts requires Acrobat Pro. Acrobat Standard supports predefined calculations (sum, product, average) but not custom JavaScript in the Calculate tab. For a full breakdown of what each plan supports, see Applying actions and scripts to PDFs on Adobe HelpX.
Where scripts run when the form is filled in Scripts execute in Adobe Acrobat desktop (Pro, Standard, and Reader) and in the Acrobat mobile app. They do not run in browser-based PDF viewers such as Chrome's built-in viewer, Firefox PDF.js, Safari, or Preview on macOS. If a recipient opens the form in one of those environments, calculated fields will not update. To ensure calculations work for all recipients, include a note in the form advising users to open it in Adobe Acrobat or Adobe Reader.
Security settings can affect script execution Acrobat allows JavaScript to be disabled at the application level. If a recipient has turned off JavaScript in their Acrobat preferences, calculation scripts will not run. See Restrict JavaScript API access in Acrobat for details on how these settings work.
For the complete official reference on Acrobat JavaScript — including all supported objects, methods, and properties — the JavaScript for Acrobat API Reference.
Was this post helpful? If the scripts here solved your problem, select Yes on the helpful prompt below — it helps the community team understand which guides are worth expanding.
Your scenario isn't listed here? Please start a new question in the Acrobat Discussions section of the community rather than replying to this thread. A new post means the right people can find it, experts can respond, and the question becomes searchable for others with the same need. Include your field names and describe the result you are trying to achieve — that gives the community what it needs to help you quickly.
