PDF Editing Issues

How to Calculate Totals by Drop-Down Category in Acrobat Forms

Algirdas JasaitisAlgirdas Jasaitis Nov 3, 2026 869 views

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.

How to Calculate Totals by Drop-Down Category in Acrobat Forms
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Prepare Form mode

Open your PDF in Acrobat and select 'Prepare Form' from the Tools menu to enter form editing mode.

2
Access Field Properties

Right-click the target subtotal field (e.g., 'Total_A') and select 'Properties' from the context menu.

3
Add Custom Calculation Script

Navigate to the 'Calculate' tab, select 'Custom calculation script', and click the 'Edit' button.

4
Enter the Loop Script

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;

5
Duplicate for other Categories

Repeat this process for your 'Total_B' through 'Total_K' fields, changing the 'A' in the script to the corresponding category letter.

Data Type Conversion: Using the Number() function inside the loop ensures that Acrobat treats the retrieved form values as numbers, preventing unexpected string concatenation errors.
Powerful PDF Form Management

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. 1. Open your PDF Form: Launch WPS Office, click on 'Open', and select your interactive PDF form from your local files.
  2. 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. 3. Trigger Calculations: As you select categories from the drop-down menus, pre-embedded calculation scripts will process automatically in the background.
  4. 4. Save and Export: Click 'Save' or 'Export to PDF' to preserve your calculated data securely for sharing or printing.
Easily fill out interactive PDF forms and trigger embedded JavaScript calculations.Highly compatible with standard Adobe Acrobat PDF files and Microsoft Office document formats.Lightweight application that loads large PDF forms instantly without system lag.
QA img-9

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.