How to Fix NaN Errors in PDF Form JavaScript Calculations
Question details
The user is encountering a 'NaN' (Not a Number) error when performing JavaScript calculations on a PDF form, and experiencing issues with clearing specific dropdown fields using a reset action.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Calculating total values in a PDF form using custom JavaScript and resetting form fields to their default state.
- Observed behavior
- The form calculation outputs 'NaN' instead of the expected numerical total because formatted text (like commas or currency symbols) is being parsed as mathematical data. Additionally, the reset button fails to clear certain multiple-choice dropdown fields.
Before modifying your form scripts or deleting fields, ensure you have saved a backup copy of your original PDF file to prevent accidental loss of complex JavaScript configurations.
Store Raw Numeric Data and Apply Built-in Field Formatting
This resolves the NaN error by ensuring JavaScript calculates raw numbers instead of text strings containing commas or currency symbols.
Mathematical operations in JavaScript require raw numerical values. When fields output numbers formatted with thousands separators or currency signs (e.g., '5,705.00'), the script reads them as text strings, resulting in a 'Not a Number' (NaN) error.
Edit your custom JavaScript calculation to output raw numeric values without thousands separators or currency symbols. For example, ensure the script passes '5705' instead of '5,705.00'.
Right-click the specific PDF form field that displays the calculated total and select 'Properties' from the context menu.
Navigate to the 'Format' tab within the Properties dialog box. Select 'Number' from the Select Format Category dropdown list, then configure your desired decimal places, separator style, and currency symbol to handle the visual display automatically.

Replace Incompatible Dropdowns with Standard Combo Boxes
Fix reset action failures by replacing incompatible multiple-choice dropdowns with standard, supported PDF form controls.
Create and Edit PDF Forms Seamlessly with WPS PDF
WPS PDF provides a comprehensive and intuitive set of tools for creating interactive PDF forms, adding calculation fields, and customizing field formatting without needing to write complex custom JavaScript.
- 1. Open your PDF Document: Launch WPS Office and open your PDF file using the WPS PDF editor.
- 2. Access the Form Toolbar: Navigate to the 'Form' tab on the top ribbon to view the interactive form controls like Text Fields, Checkboxes, and Combo Boxes.
- 3. Configure Calculation Properties: Double-click a form field to open its Properties panel. Navigate to the 'Calculate' tab to set up predefined operations (like sum or product) and the 'Format' tab to customize number display without custom code.

Frequently Asked Questions
Why does my PDF form calculation show zero instead of NaN?
This usually happens when the fields referenced in your calculation script are empty, incorrectly named, or set to an incompatible format category rather than containing invalid text strings.
Can I use custom JavaScript for currency formatting in PDF forms?
Yes, you can use the built-in AFMakeNumber() and AFNumber_Format() functions in your custom formatting scripts. However, relying on the built-in Format tab properties is generally easier and less prone to calculation errors.
Why doesn't the reset button clear all fields in my PDF form?
The reset button may not be configured to clear every field. To fix this, right-click the reset button, go to Properties > Actions, edit the 'Reset a form' action, and verify that all desired fields are explicitly checked in the selection list.




