PDF Editing Issues

How to Compare Two PDF Form Values and Return the Higher Value

Elise WilliamsElise Williams Nov 5, 2026 869 views

Question details

The user needs to evaluate the calculated sum of three form fields against the value of a fourth field, and display whichever value is higher in a fifth form field.

How to Compare Two PDF Form Values and Return the Higher Value
Product
PDF Editor
Device & OS
not provided
Scenario
Creating an interactive, fillable PDF form that requires conditional logic to determine and display the maximum value between multiple input fields.
Observed behavior
Needs the correct method or JavaScript syntax to accurately compare separated numeric fields and populate a designated final total field.
Before you start

Ensure all the relevant text fields in your PDF form are properly named (e.g., 'sumA', 'sumB') and that their format properties are set to 'Number' before applying any calculation scripts.

Solution 1Recommended

Use the Built-in Maximum Calculation Feature

If your totals are already calculated and stored in separate numeric fields, you can use the built-in Maximum function without writing any code.

This is the simplest method and works perfectly when you are comparing predefined form fields. However, it requires that the intermediate sum of the first three fields is already calculated in a distinct field.

1
Access Field Properties

Enter Form Editing mode in your PDF editor, right-click on the destination field (e.g., Field 5), and select 'Properties'.

2
Navigate to the Calculate Tab

In the Properties dialog box, click on the 'Calculate' tab.

3
Set the Maximum Function

Select the option 'Value is the' and choose 'maximum' from the dropdown menu. Click the 'Pick...' button to select the specific fields you want to compare (e.g., the field holding the sum and Field 4).

4
Save and Test

Close the properties window and test your form by entering numbers into the source fields to verify the higher value appears automatically.

Use the Built-in Maximum Calculation Feature
Calculation Order: Ensure that the fields being evaluated are calculated before the final maximum field by checking the calculation order in your form settings.
Advanced PDF Form Tools

Create and Calculate PDF Forms Easily with WPS PDF

WPS Office provides a robust PDF editor that allows you to easily create fillable forms, manage field properties, and execute JavaScript calculations, making tasks like comparing form values effortless.

  1. 1. Open the Form Editor: Launch WPS Office, open your PDF document, and navigate to the 'Form' tab on the top ribbon.
  2. 2. Insert and Configure Fields: Add a Text Field for your maximum value result, right-click it, and select 'Properties' from the context menu.
  3. 3. Apply Calculation Logic: Under the 'Calculate' tab, choose the built-in maximum function or select 'Custom calculation script' to input your JavaScript.
  4. 4. Save and Preview: Exit form editing mode, save your document, and enter numbers to test the automated calculations.
Complete PDF form creation and interactive field editing tools.Supports JavaScript for advanced mathematical and conditional field calculations.Fully compatible with standard PDF forms, Adobe Acrobat, and Microsoft Office document conversions.Lightweight, user-friendly interface available for free download.
QA img-9

Frequently Asked Questions

Why is my JavaScript calculation returning NaN (Not a Number)?

This happens when the script attempts to calculate empty fields or text strings. Adding 'Number()' and '|| 0' to your script (e.g., Number(this.getField('FieldName').value) || 0) ensures empty fields are treated as zero, preventing the NaN error.

Can I compare more than two fields at once using JavaScript?

Yes, the Math.max() function can evaluate multiple values simultaneously. You can format it as: event.value = Math.max(value1, value2, value3);

Why isn't my maximum value field updating automatically when I change the input fields?

This is typically caused by an incorrect calculation order. In your PDF editor, check the form's Calculation Order settings and ensure the source fields are calculated prior to the field displaying the maximum result.