Show a Blank PDF Form Field Outside a Range in Acrobat
Question details
Display an order quantity only when it is within the allowed range; otherwise, leave the calculated PDF form field blank.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A PDF order form calculates a quantity that must be at least 1 and no greater than a maximum quantity.
- Observed behavior
- The order field should show a valid result within the range and remain blank for an out-of-range result or invalid source input.
Open the form in Acrobat and check the exact field names in Prepare a form. Identify the source quantity, maximum quantity, and order field, as well as any existing formula that produces the result.
Add a range check to the Acrobat form calculation
Use a custom calculation script to show the quantity only when the source values are valid and the result is within the permitted range.
The example reads the result directly from a field named Quantity and the upper limit from MaxQuantity. Replace those names with the exact names in your form. If the result comes from a formula, incorporate that formula after validating its inputs instead of using the example quantity directly.
In Acrobat, open the PDF and choose All tools > Prepare a form. Double-click the order field to open its Properties dialog.
On the Calculate tab, select Custom calculation script and click Edit. Enter this script, replacing the field names as needed: var quantityText = this.getField("Quantity").valueAsString; var maximumText = this.getField("MaxQuantity").valueAsString; quantityText = quantityText.replace(/^\s+|\s+$/g, ""); maximumText = maximumText.replace(/^\s+|\s+$/g, ""); var quantity = Number(quantityText); var maximum = Number(maximumText); if (quantityText !== "" && maximumText !== "" && isFinite(quantity) && isFinite(maximum) && quantity >= 1 && quantity <= maximum) { event.value = quantity; } else { event.value = ""; }
Click OK to save the script, close the field properties, and save the PDF. In the form, test a value below 1, values at both limits, a value above the maximum, and empty or nonnumeric input; only valid in-range values should appear in the order field.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative for working with PDF and Microsoft Office files in a familiar interface. Open compatible files as you migrate your everyday document work; use Acrobat to create and test the custom calculation described above.

Frequently Asked Questions
Where do I enter a custom calculation in Acrobat?
Choose All tools > Prepare a form, double-click the output field, and open Calculate > Custom calculation script > Edit.
What happens when the quantity field is empty?
The example checks the source text before converting it to a number. If the quantity or maximum is empty, it sets the order field to an empty value instead of treating the input as zero.
Are the values 1 and the maximum included in the range?
Yes. The checks quantity >= 1 and quantity <= maximum include both limits. Change the comparison operators in the custom calculation script if a limit should be excluded.
Why does the calculation work in Acrobat but not another PDF viewer?
Some PDF viewers do not support Acrobat form JavaScript or custom calculations. Open the saved form in Acrobat and test the source fields again.
How do I use the script if my quantity is calculated by a formula?
In the order field's Calculate > Custom calculation script editor, validate the formula's source fields first, then use the formula's result in place of the example quantity. Keep the range check and empty-value assignment.




