How to Remove the Default Zero from a JavaScript PDF Form Field
Question details
The user wants to prevent a JavaScript-formatted number field in a PDF form from displaying a default '0' when opened, ensuring it remains blank while keeping its grouped number formatting intact.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating or modifying interactive PDF forms where number fields must remain blank until user input is provided.
- Observed behavior
- A JavaScript-formatted number field automatically displays a 0 as soon as the PDF document is opened.
Ensure you have access to a PDF editor with form creation capabilities and basic familiarity with the field properties menu.
Apply a Custom Format Script to Clear Zero Values
You can resolve this issue by applying a brief JavaScript snippet in the field's formatting settings to ensure the field stays blank if its value evaluates to zero.
By default, PDF number fields often display a zero to maintain numerical integrity. Overriding this behavior requires a custom format script that explicitly tells the field to show as blank when the value is exactly zero.
Open your PDF document in Form Editing mode. Right-click on the specific number field displaying the unwanted zero and select 'Properties' from the context menu.
Navigate to the 'Options' tab in the Properties dialog box. Verify that the 'Default Value' field is completely empty. If there is a '0' entered here, delete it.
Switch to the 'Format' tab. From the 'Select format category' drop-down list, choose 'Custom'. In the 'Custom Format Script' text box, type or paste the following code: if (event.value == 0) { event.value = ""; }
Click 'Close' to exit the Properties dialog box. Exit Form Editing mode and test the field by clearing its contents to confirm it remains blank instead of reverting to zero.

Easily Manage Interactive PDF Forms with WPS Office
WPS Office provides robust PDF editing tools, allowing you to easily create, modify, and format interactive form fields with full support for custom JavaScript execution.
- 1. Open PDF Editor: Launch WPS Office and open your PDF document containing the interactive forms.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the comprehensive form editing toolset.
- 3. Edit Field Properties: Double-click on the specific form field you wish to modify. This will open the Properties dialog where you can change settings.
- 4. Add JavaScript Formatting: Go to the 'Format' tab, select 'Custom', and input your required JavaScript formatting code, then save your document.

Frequently Asked Questions
Why does my PDF form field always default to zero?
PDF form fields set to 'Number' formatting automatically default to 0 to maintain numerical integrity for calculations. You can override this by clearing the field's default value and using a custom JavaScript formatting script.
Will applying this script break my number formatting?
No. The script 'if (event.value == 0) { event.value = ""; }' simply ensures the field is visually blank when empty or zero. As soon as a user inputs a valid number, your existing grouped number format settings will take effect.
Can I apply this script to multiple form fields at once?
Typically, you must open the properties of each field individually and paste the script into the Format tab. However, a faster method is to configure one field perfectly, copy it, and paste it to create new fields with identical properties.




