How to Set a PDF Form Field to Zero Above a Specific Price
Question details
The user needs a calculated PDF form field to display zero if a specific numerical threshold (such as a sales price exceeding 800,000) is met, and otherwise mirror the input value.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating a dynamically calculating PDF form that applies conditional logic to its fields.
- Observed behavior
- The field evaluates the conditional script to automatically output 0 or the original value depending on the referenced field's input.
Ensure you have a PDF editing tool that supports interactive form creation and JavaScript calculations, and verify the exact name of your reference field.
Apply a Custom Calculation Script to the PDF Field
Add a JavaScript snippet to the form field's calculation properties to automatically evaluate the condition and update the value dynamically.
To achieve conditional formatting where a field changes based on another field's value, you need to use a custom calculation script. This ensures the target field monitors the reference field in real-time and applies the if-else logic automatically.
Launch your PDF editor and enter the Form Editing mode to reveal all interactive fields in your document.
Right-click the destination field (the one that should display zero or the copied value) and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab to view calculation options.
Select 'Custom calculation script' and click the 'Edit' button. Enter the following code: var salesPrice = Number(this.getField("SalesPrice").valueAsString); event.value = (salesPrice > 800000) ? 0 : salesPrice;
Click 'OK' to save the script, then close the Properties dialog. Exit form editing mode and enter a test value in the 'SalesPrice' field to ensure the calculation works.

Create and Manage Smart PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, allowing you to easily add text fields, manage form properties, and handle interactive documents without specialized software.
- 1. Open WPS Office: Launch the WPS Office application and navigate to the 'PDF' tab.
- 2. Load your PDF: Open the PDF document you wish to edit or add form fields to.
- 3. Access Form Tools: Click on the 'Form' tab in the top ribbon to access interactive field insertion tools.
- 4. Edit Properties: Double-click any inserted text field to open its properties and configure its behavior.

Frequently Asked Questions
Why isn't my PDF form calculation updating automatically?
If fields aren't updating, the calculation order may be incorrect. In your PDF form properties, ensure the fields are set to calculate in the logical order of operations, especially if one calculated field depends on another.
Can I perform basic math functions in a PDF without JavaScript?
Yes. Most advanced PDF editors have a 'Calculate' tab in the field properties that lets you select basic pre-defined functions like Sum, Product, Average, Minimum, or Maximum without needing to write any code.
How do I find the exact name of a field in my PDF?
Enter form editing mode in your PDF software. The field names are typically displayed directly over the form fields. You can also right-click the field and check the 'General' tab in its Properties to see the exact name.
What happens if a user inputs text instead of numbers in the reference field?
If the script uses the Number() function, text input will generally be converted to NaN (Not a Number), which may cause the calculation to fail or evaluate to zero. It is recommended to set the reference field's format to 'Number' to prevent invalid inputs.




