How to Combine PDF Form Calculations and Hide Zero Values with JavaScript
Question details
The user needs to calculate a total from a quantity and unit price in a PDF form while preventing the result field from displaying $0.00 when no quantity is entered.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or editing an interactive PDF form that involves automated mathematical calculations and requires a clean look without placeholder zero values.
- Observed behavior
- The PDF form calculates $0.00 by default for empty fields. Because the software restricts users to only one calculation script per field, it is difficult to calculate the total and simultaneously modify the visibility of zero values.
Ensure you have access to a PDF editor that supports JavaScript for interactive forms, such as Adobe Acrobat Pro, and back up your original PDF before applying custom scripts.
Use a Single Custom JavaScript for Calculation and Formatting
Combine the multiplication logic and the zero-hiding condition into a single custom calculation script within the target field.
Since PDF form fields typically only accept one calculation script, you cannot separate the multiplication logic and the display logic into different calculation tabs. By writing a custom JavaScript, you can perform the math and then immediately check if the result is zero. If it is, the script clears the field.
This approach keeps your document clean and prevents unwanted $0.00 values from cluttering uncompleted sections of your form.
Open your PDF form in your PDF editor (e.g., Adobe Acrobat) and enter the 'Prepare Form' mode to view all interactive fields.
Right-click the target calculation field (such as the Total field) and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab to manage the math logic for that specific field.
Select the 'Custom calculation script' option, click the 'Edit' button, and paste the following code: `event.value = Number(this.getField("Qty1").valueAsString) * Number(this.getField("UnitPrice1").valueAsString); if (event.value == 0) event.value = "";`
Click 'OK' to save the script and close the Properties window. Test the form by entering and deleting quantities to ensure the total calculates correctly and hides the zero value when empty.

Manage and Edit PDF Forms Seamlessly with WPS Office
WPS Office provides a powerful built-in PDF editor that allows you to view, fill, and manage interactive PDF forms effortlessly. Whether you are dealing with calculated fields or simply need to sign a document, WPS Office offers a seamless, lightweight experience.
- 1. Open Your PDF: Launch WPS Office and open your interactive PDF form document.
- 2. Access Form Tools: Navigate to the 'Form' or 'PDF Edit' tab to interact with form fields seamlessly.
- 3. Fill and Calculate: Fill in the required fields; calculations will automatically update based on the embedded document scripts.
- 4. Save and Export: Save your completed PDF securely or export it directly to other formats like Word or Excel.

Frequently Asked Questions
Why does my PDF form show $0.00 by default?
PDF form fields set to calculate a product will multiply empty fields as zero. Without a specific script to clear or hide it, standard formatting displays this zero result as $0.00.
Can I use multiple calculation scripts on a single PDF field?
No, standard PDF editors only allow one calculation script per field. You must combine multiple actions, such as calculating totals and hiding zero values, into a single custom JavaScript.
How do I hide an entire section of the form if it is not used?
To hide entire sections, you need to use the display or calculate scripts of the individual fields to change the visibility properties (e.g., setting the display property to hidden) based on specific conditions, rather than just clearing the value.
Do JavaScript form calculations work on mobile PDF viewers?
It depends on the app. While desktop PDF editors fully support JavaScript calculations, many basic mobile PDF viewers do not execute embedded JavaScript. It is recommended to use robust applications like WPS Office or Adobe Acrobat Reader on mobile to ensure form scripts function properly.




