How to Create a Conditional If-Then Formula in an Acrobat PDF Form
Question details
The user needs to set up a PDF form to calculate the sum of three fields and conditionally display the result in one of two distinct fields based on whether the total sum is positive or negative.

- Product
- Adobe Acrobat PDF Forms
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms requiring conditional mathematical calculations.
- Observed behavior
- The form must dynamically route the calculated sum to either 'Security_Due_to_Tenant' for positive results or 'Security_Due_to_Building' for negative results.
Ensure you have a PDF editor that supports JavaScript form calculations, such as Adobe Acrobat Pro, and verify the exact names of your source form fields before adding the scripts.
Apply Custom JavaScript for Conditional Calculations
Use JavaScript in the form field properties to calculate the sum and apply an if-then condition to display the result in the correct target field.
PDF forms use JavaScript for advanced conditional calculations. You will need to apply a specific script to each of the destination fields so they independently evaluate whether to display the calculated sum or remain blank.
Open your PDF in 'Prepare Form' mode. Right-click the 'Security_Due_to_Tenant' field and select 'Properties'.
Navigate to the 'Calculate' tab. Select 'Custom calculation script', click 'Edit', and enter the following code: var v1 = Number(this.getField("Security_On_Hand").valueAsString); var v2 = Number(this.getField("Total_Credits").valueAsString); var v3 = Number(this.getField("Total_Charges").valueAsString); var sum = v1 + v2 + v3; event.value = (sum > 0) ? sum : "";
Right-click the 'Security_Due_to_Building' field, go to Properties > Calculate > Custom calculation script. Paste the same code, but change the final line to: event.value = (sum < 0) ? sum : "";
Exit 'Prepare Form' mode and enter test values into the Security_On_Hand, Total_Credits, and Total_Charges fields to verify the values route correctly.

Easily Manage and Edit PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to view, fill, edit, and manage interactive PDF forms effortlessly.
- 1. Open WPS PDF: Launch WPS Office and navigate to the PDF tab.
- 2. Load Your PDF Form: Open your interactive PDF form document directly within the application.
- 3. Fill and Manage Fields: Use the built-in form tools to interact with the fields, input data, and manage form elements smoothly.
- 4. Save and Export: Save your filled PDF securely or export it to share with others.

Frequently Asked Questions
Why isn't my PDF form calculation updating automatically?
Ensure that the calculation order in your PDF editor is set correctly. If one field relies on another, the source fields must calculate first. Also, verify that automatic calculations are enabled in your PDF viewer's preferences.
Can I use basic built-in calculations instead of JavaScript?
Yes, for simple sums, products, or averages, you can use the built-in 'Value is the sum of' option in the Calculate tab. However, conditional logic (such as if-then statements) strictly requires custom JavaScript.
How do I find the exact name of a form field in Acrobat?
Enter the 'Prepare Form' mode. The names of all fields will be displayed directly over the text boxes. You can double-click any field to view or edit its exact name in the Properties dialog.




