How to Create If-Then PDF Form Calculations Based on Field Values
Question details
The user needs to set up conditional calculations in a PDF form where a calculated field (like a Distortion Factor) dynamically changes based on another field's selection (like Plate Gauge) and a specific user input (Repeat value).

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms that require conditional logic (If-Then) to calculate output values based on multiple user inputs.
- Observed behavior
- The form needs to dynamically apply different formulas or constants depending on dropdown selections or text field inputs, requiring the configuration of a custom calculation script.
Ensure you have mapped out the exact mathematical formula, identified all constants, and noted the exact field names used in your PDF form before writing the calculation script.
Use a Custom JavaScript Calculation for Conditional Logic
Use the custom calculation script feature in your PDF editor to apply if-then conditional logic for calculating field values.
Interactive PDF forms require JavaScript to execute complex if-then logic. By defining your formulas clearly, you can write a script that checks the value of one field (e.g., Plate Gauge) and applies the correct mathematical operation using another field (e.g., Repeat value).
Open your PDF form in Prepare Form mode. Note the exact names of your input fields (e.g., 'PlateGauge', 'RepeatValue') and the target field where the calculation will appear.
Right-click the target field (e.g., 'DistortionFactor') and select 'Properties'. Navigate to the 'Calculate' tab.
Choose the 'Custom calculation script' radio button and click the 'Edit' button to open the JavaScript editor.
Enter a script using standard JavaScript if/else syntax. For example: `var gauge = this.getField('PlateGauge').valueAsString; var repeat = Number(this.getField('RepeatValue').value); if (gauge == '067') { event.value = repeat * 1.5; } else if (gauge == '107') { event.value = repeat * 2.0; } else { event.value = 0; }`
Save the script, exit the form editing mode, and test all combinations of your input fields to ensure mathematical precedence and outputs are correct.

Fill and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF Editor that allows you to easily view, fill, and manage interactive PDF forms. With cross-platform support, you can handle your business documents efficiently without expensive subscriptions.
- 1. Open the PDF: Launch WPS Office and open your interactive PDF form using the WPS PDF Editor.
- 2. Access Form Fields: Navigate through the document to view and interact with available form fields, dropdowns, and text boxes.
- 3. Fill and Save: Input your data into the form fields. The built-in conditional logic of the PDF will automatically calculate values. Save your completed document or export it as needed.

Frequently Asked Questions
Why is my PDF form calculation returning a zero or blank?
This usually happens if the field names in your JavaScript do not exactly match the actual field names in the form, or if the input fields are empty and not handled correctly in your script's logic.
Can I use standard math formulas instead of JavaScript for PDF forms?
For simple calculations like sum or product, you can use the built-in 'Value is the [sum] of the following fields' option in the Calculate tab. However, dynamic if-then conditional logic strictly requires a Custom Calculation Script.
How do I format the output of my calculated PDF field?
In the Field Properties dialog of your target field, go to the 'Format' tab. You can select Number, Percentage, or Custom formatting to ensure your calculated result displays with the correct decimal places or currency symbols.




