How to Calculate a PDF Form Field Using One of Two Input Fields
Question details
The user needs to set up a PDF calculation field that dynamically pulls its input from Field 2 if it contains a value, or Field 1 otherwise, and multiplies the selected value by 1.25.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF form where a calculated field relies on conditional logic to determine which user input field to use.
- Observed behavior
- The form field evaluates the blank status of the fields and returns the correct mathematically calculated value using custom JavaScript.
Ensure you are using a PDF editor that supports form creation and custom JavaScript calculations, and verify the exact names of your input fields before writing the script.
Apply a Custom Calculation Script in PDF Field Properties
Add conditional JavaScript to your target form field to evaluate the inputs and apply the 1.25 multiplier accordingly.
To apply conditional logic in a PDF form, standard mathematical functions are not enough. You must use a custom JavaScript calculation script that checks the status of your fields.
Enter the form editing mode in your PDF editor. Right-click the calculation field where you want the final result to appear and select 'Properties'.
In the Properties dialog, click on the 'Calculate' tab to view the calculation options for this field.
Choose the option labeled 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor window.
Type the following script, adjusting the field names to match yours exactly: var v1 = this.getField('Field 1').valueAsString; var v2 = this.getField('Field 2').valueAsString; if (v2 == '') { event.value = Number(v1) * 1.25; } else { event.value = Number(v2) * 1.25; }
Click 'OK' to save the script, then close the Properties dialog. Exit form editing mode and input data into Field 1 and Field 2 to verify that the calculation works correctly.

Easily Manage PDF Forms and Calculations with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily create interactive forms, add text fields, and configure properties for complex document workflows without switching applications.
- 1. Download WPS Office: Install WPS Office for free from the official website and open your PDF document.
- 2. Access the Form Menu: Navigate to the 'Form' tab in the top ribbon to view all available form creation tools.
- 3. Edit Form Fields: Double-click any text field to access its properties, where you can customize its appearance and behavior.

Frequently Asked Questions
Why isn't my PDF form calculation updating automatically?
If your calculation isn't updating, ensure that the 'Automatically calculate field values' preference is enabled in your PDF editor. Additionally, verify your field calculation order, as an incorrect order can prevent dependent calculations from processing correctly.
Can I use standard math operators instead of JavaScript for PDF calculations?
Yes, for simple mathematical operations like addition, multiplication, or calculating an average, most PDF editors provide built-in options in the 'Calculate' tab. You only need to use custom JavaScript when your form requires conditional logic, such as choosing between two different fields.
How do I prevent my PDF calculation script from displaying 0 when both fields are empty?
If both fields are empty, the script converts the empty strings to 0 using the Number() function. If you prefer the field to remain completely blank instead, you can add an initial 'if' condition to check if both v1 and v2 are empty, and set event.value to an empty string ('') before proceeding with the math.




