How to Calculate Total Cost from Quantity in an Acrobat PDF Form
Question details
The user wants to automatically calculate a total price in a PDF form field by multiplying the values entered in the quantity and unit price fields.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms that require automatic calculations for invoices, order forms, or price quotes.
- Observed behavior
- The user needs to implement a custom script or calculation method to dynamically output the product of two form fields into a third total field.
Ensure you are using a PDF editor that supports form field properties and custom JavaScript, and that your form already contains named fields for Quantity, Unit Price, and Total.
Use a Custom JavaScript Calculation Script
Add custom JavaScript code to the Total field to dynamically multiply the values of the Quantity and Unit Price fields.
This method gives you the most flexibility and is perfect if you need to perform more complex calculations in the future.
Right-click the 'Total' field in your PDF form and select 'Properties' from the context menu.
Click on the 'Calculate' tab located at the top of the Text Field Properties dialog box.
Choose the 'Custom calculation script' option and click the 'Edit' button.
Input the following script: var quantity = Number(this.getField('Quantity').value); var price = Number(this.getField('UnitPrice').value); event.value = quantity * price;
Click 'OK' to save the script, then close the properties window. Test the form by entering a quantity of 3 and a unit price of 4 to verify that the total automatically updates to 12.

Use the Built-in Product Function
Use the built-in calculation settings in the PDF editor to automatically multiply two fields without writing any code.
Fill and Manage PDF Forms Easily with WPS Office
WPS Office features a powerful built-in PDF reader and editor that effortlessly handles interactive PDF forms, including those with advanced JavaScript calculations, making document processing fast and easy.
- 1. Open PDF in WPS Office: Launch WPS Office and open your interactive PDF document containing the form fields.
- 2. Fill the Form Fields: Click directly into the text fields, such as Quantity or Unit Price, and input your numerical values.
- 3. View Auto-Calculations: WPS PDF will seamlessly process the embedded calculation rules or JavaScript to automatically generate the correct Total Cost.

Frequently Asked Questions
Why is my PDF form calculation not updating automatically?
This usually happens if the calculation order is incorrect or if JavaScript is disabled in your PDF viewer. Check your application settings to ensure JavaScript is enabled, and verify that the Total field is calculated after the Quantity and Unit Price fields.
Can I format the total field to show currency symbols?
Yes. In the Total field's properties, navigate to the 'Format' tab. Choose 'Number' or 'Special', and you can select a currency symbol and specify the number of decimal places you want to display.
Does the custom script work if the fields are left blank?
If fields are left blank, the script usually treats them as zero, resulting in a total of zero. To prevent this, you can add an 'if' statement in your JavaScript to only calculate the total when both fields have numerical values.




