Calculate PDF Form Totals From Two Dropdowns With JavaScript
Question details
Calculate separate installation and monthly fee totals from computer and display dropdown selections in a PDF form.

- Product
- PDF form with JavaScript calculation fields
- Device & OS
- not provided
- Scenario
- A form user selects one computer product and one display product, each with an installation price and a monthly price.
- Observed behavior
- The form should display the combined installation fee and combined monthly fee in separate text fields.
Open the PDF in an editor that supports Acrobat-compatible custom calculation scripts, such as Adobe Acrobat Pro. Check the exact field names and dropdown export values; the names and prices below are examples that must be replaced with your own.
Add custom calculation scripts to the PDF total fields
Use two calculated text fields to add the installation and monthly prices for the selected products.
The examples use dropdown fields named Computer and Display, with export values computer-basic, computer-pro, display-basic, and display-pro. The sample prices are 100 and 200 for computer installation, 50 and 80 for display installation, 10 and 20 for computer monthly fees, and 5 and 8 for display monthly fees.
An unselected or unrecognized value contributes zero. Add an entry for every product and replace the sample amounts with your actual prices.
In Adobe Acrobat Pro, open the PDF and choose All tools > Prepare a form. Open Properties for each dropdown, check its name under General, and check or set each item’s export value under Options.
In Prepare a form, add two text fields named InstallationTotal and MonthlyTotal, or use your existing total fields. Open each field’s Properties and choose a number or currency format under Format.
Open InstallationTotal Properties > Calculate, select Custom calculation script, and click Edit. Enter this script, replacing field names, export values, and prices as needed: var computer = this.getField("Computer").valueAsString; var display = this.getField("Display").valueAsString; var computerPrice = {"computer-basic": 100, "computer-pro": 200}; var displayPrice = {"display-basic": 50, "display-pro": 80}; var a = Object.prototype.hasOwnProperty.call(computerPrice, computer) ? computerPrice[computer] : 0; var b = Object.prototype.hasOwnProperty.call(displayPrice, display) ? displayPrice[display] : 0; event.value = a + b;
Open MonthlyTotal Properties > Calculate, select Custom calculation script, and click Edit. Enter this script, using the same field names and export values but your monthly prices: var computer = this.getField("Computer").valueAsString; var display = this.getField("Display").valueAsString; var computerPrice = {"computer-basic": 10, "computer-pro": 20}; var displayPrice = {"display-basic": 5, "display-pro": 8}; var a = Object.prototype.hasOwnProperty.call(computerPrice, computer) ? computerPrice[computer] : 0; var b = Object.prototype.hasOwnProperty.call(displayPrice, display) ? displayPrice[display] : 0; event.value = a + b;
Save the PDF, leave Prepare a form, and select different combinations in both dropdowns. For example, the sample computer-basic and display-pro selections should produce an installation total of 180 and a monthly total of 18.

Manage Product Price Tables With WPS Office
WPS Office is a free, lightweight alternative for working with product lists and price tables in a familiar interface. It supports common Microsoft Office formats for easier migration, but it should not be assumed to create or run Acrobat-specific PDF calculation scripts.

Frequently Asked Questions
Why do the totals stay at zero after I select a product?
In Prepare a form, open each dropdown’s Properties > Options and compare its export values with the keys in both scripts. The example scripts return zero for values that are not in the price tables.
Where do I add a custom calculation script in Acrobat?
Choose All tools > Prepare a form, open the total text field’s Properties, and select Calculate > Custom calculation script > Edit. Add a separate script to each total field.
Can I show the totals as currency?
Yes. Open each total field’s Properties, select the Format tab, and choose a number or currency format with the decimal places and currency symbol you need.
Will the calculations work in every PDF viewer?
No. The viewer must support the form’s Acrobat-compatible JavaScript and allow it to run. Test the saved PDF in the viewer your recipients will use.




