How to Show a PDF Calculated Field Only Above Zero Using JavaScript
Question details
The user needs a calculated field in a PDF form to remain blank when the sum of its source fields is zero or when all source fields are empty.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms with calculated fields that should only display positive values greater than zero.
- Observed behavior
- By default, the calculated field displays '0' even when source fields are blank or their sum equals zero, which clutters the form.
Ensure you have noted the exact system names of your source input fields (e.g., 'FieldA', 'FieldB') before writing your custom calculation script.
Use Custom JavaScript to Check the Total Value
This method calculates the sum of all designated fields and applies a condition to only display the result if it is strictly greater than zero.
Instead of relying on the default sum function, you can write a short custom JavaScript. This allows the PDF to evaluate the final calculated number and replace any zero or negative value with an empty string, keeping your form clean.
Open your PDF editor, enter Form Editing mode, and right-click the target calculated field. Select 'Properties' from the context menu.
Navigate to the 'Calculate' tab inside the Properties window and select the 'Custom calculation script' option.
Click the 'Edit' button and define your total by summing the input fields. Type: var total = Number(this.getField("a").value) + Number(this.getField("b").value) + Number(this.getField("c").value); (replace 'a', 'b', and 'c' with your actual field names).
On the next line, add the condition to hide zero values: event.value = total > 0 ? total : "";
Click 'OK' to save the script, close the properties window, and test your form by entering values in the source fields.

Use Conditional Statements to Check for Blank Inputs
An alternative script that checks if all source input fields are currently empty before performing any calculations.
Create and Manage Smart PDF Forms in WPS Office
WPS Office provides a comprehensive and user-friendly PDF editor. You can easily create interactive forms, add text fields, configure calculations, and manage your document workflows smoothly without requiring heavy or expensive software.
- 1. Open PDF: Launch WPS Office and open your PDF document.
- 2. Access form tools: Navigate to the 'Form' tab on the top toolbar to access various form editing features.
- 3. Insert and configure fields: Insert text fields, checkboxes, or dropdowns. Double-click any field to configure its properties and calculations.
- 4. Save document: Once your form logic is set up, save the fillable PDF and distribute it to your users.

Frequently Asked Questions
Why does my PDF calculated field show a zero instead of staying blank?
By default, simple sum calculations in PDF forms treat empty fields as zero. When it adds them up, it results in a '0' output. Using custom JavaScript allows you to override this behavior and force the field to remain blank.
Where do I find the custom calculation script option in a PDF?
While in the Form Editing mode of your PDF editor, right-click the specific text field, select 'Properties', click the 'Calculate' tab, and then check the radio button for 'Custom calculation script'.
Do I need to know JavaScript to edit PDF forms?
For basic form features like simple sums, averages, or products, no coding is required. However, writing conditional rules (like hiding fields based on specific numerical outcomes) requires basic JavaScript knowledge.




