PDF Editing Issues

How to Calculate a PDF Form Field Using One of Two Input Fields

Tauseeq MagsiTauseeq Magsi Nov 5, 2026 869 views

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.

How to Calculate a PDF Form Field Using One of Two Input Fields
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

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'.

2
Navigate to the Calculate Tab

In the Properties dialog, click on the 'Calculate' tab to view the calculation options for this field.

3
Select Custom Script Option

Choose the option labeled 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor window.

4
Input the JavaScript Code

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; }

5
Save and Test

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.

Apply a Custom Calculation Script in PDF Field Properties
Script Explanation: Using the 'valueAsString' property is crucial here, as it allows the script to accurately detect whether the optional field is entirely blank, rather than treating a zero or unformatted value as empty.
Advanced PDF Form Tools

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. 1. Download WPS Office: Install WPS Office for free from the official website and open your PDF document.
  2. 2. Access the Form Menu: Navigate to the 'Form' tab in the top ribbon to view all available form creation tools.
  3. 3. Edit Form Fields: Double-click any text field to access its properties, where you can customize its appearance and behavior.
Create, edit, and fill interactive PDF forms effortlessly.Highly compatible with standard PDF formats and Adobe Acrobat forms.Lightweight software that offers a seamless user experience for document management.
microsoft office alternative - wps office

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.