How to Calculate Totals by Drop-Down Category in Acrobat Forms
Question details
Need to sum up repeated form fields conditionally based on the category selected from a drop-down menu (A through K) using Acrobat JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that automatically calculates categorized subtotals from a list of inputted earnings and dropdown selections.
- Observed behavior
- Users need a script to iterate through dynamically named fields (e.g., Category.0, Category.1) to find matching drop-down values and add their corresponding numerical amounts.
Ensure all your repeated PDF form fields are named consistently with an index suffix (e.g., Category.0, Category.1, Amount_Earned.0) so that JavaScript loops can accurately process them.
Use a Custom JavaScript Calculation Loop
Implement a custom JavaScript script in the Total field that loops through all rows, checks the category dropdown, and sums matching amounts.
This is the most efficient method for calculating conditional sums in Acrobat. It prevents the need to create excessive hidden fields and keeps your PDF lightweight.
Be sure to use the double equals sign (==) for comparison. Using a single equals sign (=) will overwrite the category field instead of checking its value.
Open your PDF in Acrobat and select 'Prepare Form' from the Tools menu to enter form editing mode.
Right-click the target subtotal field (e.g., 'Total_A') and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab, select 'Custom calculation script', and click the 'Edit' button.
Paste the following script: var total = 0; for (var i = 0; i < 12; i++) { if (this.getField('Category.' + i).value == 'A') total += Number(this.getField('Amount_Earned.' + i).value) || 0; } event.value = total;
Repeat this process for your 'Total_B' through 'Total_K' fields, changing the 'A' in the script to the corresponding category letter.
Use Hidden Text Fields as a Workaround
Create intermediary hidden fields to capture amounts for specific categories, which can then be summed using built-in Acrobat functions.
Fill and Manage Interactive PDF Forms with WPS Office
While creating advanced JavaScript calculations requires dedicated form builders, WPS Office provides an incredibly intuitive PDF editor to effortlessly view, fill, and modify complex interactive PDF forms containing built-in scripts.
- 1. Open your PDF Form: Launch WPS Office, click on 'Open', and select your interactive PDF form from your local files.
- 2. Fill the Fields: Click into any text field or drop-down menu to input your data. WPS PDF automatically supports standard form field inputs.
- 3. Trigger Calculations: As you select categories from the drop-down menus, pre-embedded calculation scripts will process automatically in the background.
- 4. Save and Export: Click 'Save' or 'Export to PDF' to preserve your calculated data securely for sharing or printing.

Frequently Asked Questions
Why is my custom Acrobat calculation returning an error or zero?
This usually happens if the field names referenced in your JavaScript do not exactly match the field names in your form. It can also occur if you used a single equals sign (=) instead of double (==) for the category comparison.
Does the getField().value method always return a numerical amount?
Not necessarily. If a user leaves a field blank, it may return a string. Wrapping the extraction in a Number() function, such as Number(this.getField('Amount_Earned.0').value), forces the value into a numerical format for accurate addition.
Can I use this same logic to multiply amounts based on a drop-down?
Yes. You can modify the custom calculation script to perform multiplication (*), division (/), or subtraction (-) inside the conditional loop by simply changing the arithmetic operator applied to your total variable.




