PDF Editing Issues

How to Create a Conditional If-Then Formula in an Acrobat PDF Form

Phi Hung VoPhi Hung Vo Nov 2, 2026 869 views

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.

How to Create a Conditional If-Then Formula in a PDF Form
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.
Before you start

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.

Solution 1Recommended

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.

1
Access Field Properties

Open your PDF in 'Prepare Form' mode. Right-click the 'Security_Due_to_Tenant' field and select 'Properties'.

2
Add Script for Positive Results

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 : "";

3
Add Script for Negative Results

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 : "";

4
Test the Form Fields

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.

Apply Custom JavaScript for Conditional Calculations
Script Formatting: Ensure the field names in the script match your actual PDF form fields exactly, as JavaScript is case-sensitive.
Powerful PDF Editor

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. 1. Open WPS PDF: Launch WPS Office and navigate to the PDF tab.
  2. 2. Load Your PDF Form: Open your interactive PDF form document directly within the application.
  3. 3. Fill and Manage Fields: Use the built-in form tools to interact with the fields, input data, and manage form elements smoothly.
  4. 4. Save and Export: Save your filled PDF securely or export it to share with others.
Support for filling interactive PDF forms and text fieldsFully compatible with standard Adobe PDF formatsLightweight application for seamless PDF managementIntegrated closely with Word, Excel, and PowerPoint alternatives
microsoft office alternative - wps office

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.