Display a Message When Mileage Fields Match in Adobe Acrobat
Question details
Display one message when two mileage form fields match and another when they differ.

- 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.
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.
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.
In Acrobat, open the PDF and select Tools > Prepare Form, or select Prepare a form from the All tools panel.
Double-click the text field that will display the result, then select the Calculate tab.
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"; }
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.

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.

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.




