How to Add Another Field to an Acrobat JavaScript Calculation
Question details
The user wants to modify an existing PDF form calculation to add the value of an additional field to the result of a multiplication.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Editing form field calculation scripts to sum multiple values.
- Observed behavior
- The user needs the correct JavaScript syntax to append an addition operation to an existing multiplication formula in a PDF.
Ensure you know the exact field name of the new field you want to add, as JavaScript in PDF forms is strictly case-sensitive.
Update the Custom Calculation Script
Use the plus operator and ensure all field values are treated as numbers to prevent string concatenation.
When adding fields in PDF JavaScript, you must wrap your field references in the Number() function. Without it, the plus operator might concatenate the values as text strings (e.g., turning 1 + 2 into 12) instead of performing mathematical addition.
Right-click the result field where the calculation happens and select 'Properties'.
Click on the 'Calculate' tab and ensure 'Custom calculation script' is selected.
Click the 'Edit' button and append your new field using this format: + Number(this.getField("YourFieldName").value);
For example, update your script to: event.value = Number(this.getField("Net").value) * Number(this.getField("%broker").value) / 100 + Number(this.getField("Totalexp").value); Make sure to replace 'Totalexp' with your actual field name.

Edit and Fill PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to view, edit, fill out, and interact with PDF forms effortlessly, ensuring calculations and scripts run smoothly.
- 1. Open WPS PDF: Launch WPS Office and open your interactive PDF form.
- 2. Access Form Fields: Navigate to the 'Form' tab to interact with or modify form fields.
- 3. Fill and Calculate: Enter your values; WPS PDF natively supports automatic calculation scripts embedded in the document.

Frequently Asked Questions
Why is my PDF JavaScript adding values as text strings instead of numbers?
If you do not wrap your field values in the Number() function, JavaScript may treat the form inputs as text. This results in string concatenation (e.g., '1' + '2' = '12') instead of mathematical addition.
How do I fix a syntax error in my PDF calculation script?
Double-check that all parentheses are properly closed, semicolons are placed at the end of statements, and the field names inside this.getField("...") match the form field names exactly, including upper and lower cases.
Can I use standard mathematical operators in PDF JavaScript?
Yes, you can use standard operators such as + for addition, - for subtraction, * for multiplication, and / for division within your custom PDF calculation scripts.




