PDF Editing Issues

How to Fix NaN Errors in PDF Form JavaScript Calculations

Tauseeq MagsiTauseeq Magsi Nov 5, 2026 869 views

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.

How to Fix NaN Errors in PDF Form JavaScript Calculations
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 you start

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.

Solution 1Recommended

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.

1
Remove JavaScript Text Formatting

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'.

2
Access Field Properties

Right-click the specific PDF form field that displays the calculated total and select 'Properties' from the context menu.

3
Configure Number Format

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.

Store Raw Numeric Data and Apply Built-in Field Formatting
Understanding JavaScript Limitations: Using the built-in 'Format' tab properties separates the underlying numerical value from its visual presentation, preventing data type conflicts during calculations.
Create Interactive Forms

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. 1. Open your PDF Document: Launch WPS Office and open your PDF file using the WPS PDF editor.
  2. 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. 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.
Easily insert combo boxes, list boxes, and text fields into any PDF document.Configure automatic field calculations and number formatting via a simple visual interface.Fully compatible with standard Adobe Acrobat PDF form formats and logic.Lightweight, fast editing experience on both desktop and mobile platforms.
QA img-9

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.