PDF Editing Issues

Compare a Calculated PDF Field With 30 in Acrobat JavaScript

Huma Ashraf ChHuma Ashraf Ch Nov 19, 2026 868 views

Question details

The user needs an Acrobat JavaScript condition that writes custom text to another PDF form field when a calculated value is above or below 30.

Compare a Calculated PDF Field With 30 in Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A calculated PDF form field is compared with 30 to determine the text shown in a second field.
Observed behavior
The second field should show the appropriate custom text for values above or below 30, with an explicit outcome for a value of 30.
Before you start

Identify the exact names of the calculated source field and the text field that will display the result. Open the PDF in a version of Acrobat that lets you edit form fields, and check that JavaScript is enabled in Acrobat preferences.

Solution 1Recommended

Add a comparison script to the destination field

Use a custom calculation script to display different text above and below 30 without replacing the source field's existing calculation.

1
Open the destination field

In Acrobat, open the PDF and choose All tools > Prepare a form. Open Properties for the destination text field, such as field "28".

2
Add the calculation script

On the Calculate tab, select Custom calculation script and click Edit. Replace "Calculated" with the exact source field name, then enter: var raw = this.getField("Calculated").value; if (raw === "" || raw == null || isNaN(Number(raw))) { event.value = ""; } else if (Number(raw) < 30) { event.value = "Text for below 30"; } else if (Number(raw) > 30) { event.value = "Text for above 30"; } else { event.value = ""; // Value is exactly 30 }

3
Set the calculation order

In Prepare a form, use More > Set Field Calculation Order and place the calculated source field before the destination field. Menu names may vary by Acrobat version.

4
Test the form

Save the PDF, exit form editing, and enter values that produce results below, above, and equal to 30. Confirm that the destination field displays the intended text.

Add a comparison script to the destination field
Choose what happens at 30: The example clears the destination field when the value is exactly 30, blank, or not numeric. Replace the final empty string if you want a message at exactly 30.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility helps you move existing files into your workflow, though it does not fix Acrobat JavaScript behavior.

Open and work with PDF documents alongside Office filesCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFamiliar interface for an easier transition from Microsoft OfficeFree, lightweight suite for everyday document tasks
microsoft office alternative - wps office

Frequently Asked Questions

How do I run the same action for every value except 30?

After checking that the value is numeric, use a condition such as if (Number(raw) != 30). This includes values both below and above 30.

Why is the destination field showing an old result?

In Prepare a form, open More > Set Field Calculation Order and make sure the source calculated field comes before the destination field.

What does event.value refer to in the example?

In the destination field's custom calculation script, event.value is the value that will be displayed in that destination field. The script reads the source separately with this.getField("Calculated").value.

Can I show a message when the value is exactly 30?

Yes. Replace the empty string in the final else branch with your message, such as event.value = "Value is 30".