PDF Editing Issues

Display a Message When Mileage Fields Match in Adobe Acrobat

Olivia MillerOlivia Miller Nov 19, 2026 868 views

Question details

Display one message when two mileage form fields match and another when they differ.

Display a Message When Mileage Fields Match in Adobe Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form contains two mileage fields and a separate field for a comparison message.
Observed behavior
The message field should remain blank until both mileage values are entered, then show whether they match.
Before you start

Open the PDF in Adobe Acrobat and check the exact names of the two mileage fields in Prepare a Form. Add a separate text field for the message if the form does not already have one.

Solution 1Recommended

Add a custom calculation script to the message field

Use this solution to update a message field when either mileage value changes.

The script compares the mileage entries as numbers and leaves the message blank until both fields contain a value. It assumes commas, if present, are thousands separators.

1
Open the form editor

In Acrobat, open the PDF and select Tools > Prepare Form, or select Prepare a form from the All tools panel.

2
Open the message field properties

Double-click the text field that will display the result, then select the Calculate tab.

3
Enter the calculation script

Select Custom calculation script and click Edit. Paste the following script, replacing Mileage1 and Mileage2 with the exact field names: var a = this.getField("Mileage1").valueAsString.replace(/^\s+|\s+$/g, ""); var b = this.getField("Mileage2").valueAsString.replace(/^\s+|\s+$/g, ""); if (a === "" || b === "") { event.value = ""; } else { var numA = Number(a.replace(/,/g, "")); var numB = Number(b.replace(/,/g, "")); event.value = isFinite(numA) && isFinite(numB) && numA === numB ? "Mileage matches" : "Error"; }

4
Save and test the form

Click OK to close the script editor and field properties, then close Prepare Form. Enter matching and different mileage values in the two fields and save the PDF.

Add a custom calculation script to the message field
Check calculation settings: If the message does not update, check Preferences > Forms and make sure Automatically calculate field values is enabled. The script also displays Error for nonnumeric entries.
Free Microsoft Office alternative

Work with PDF and Office files in WPS Office

WPS Office is a free, lightweight alternative for working with PDFs and Office documents in a familiar interface. Its format compatibility can make migration easier, but it does not replace the Acrobat JavaScript calculation described above.

Open and review PDF forms alongside other documentsCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for an easier transition from Microsoft OfficeFree, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Where do I find the mileage field names?

Open Tools > Prepare Form in Acrobat and inspect the fields in the form editor. Double-click a field and check its name on the General tab.

Why does the message stay blank after I enter a value?

The script leaves the message blank until both mileage fields contain a value. Enter a value in each field and commit the entry by moving to another field.

Can I change the text shown in the message field?

Yes. Open the message field's Properties > Calculate > Custom calculation script > Edit, and replace "Mileage matches" or "Error" with your preferred text.

Why doesn't the message update when I change a mileage value?

Check that the script uses the exact mileage field names, then open Preferences > Forms and enable Automatically calculate field values. Also confirm that JavaScript is enabled in Acrobat's JavaScript preferences.