PDF Editing Issues

Fix NaN Error in PDF Form Calculation Scripts

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 869 views

Question details

The user needs to correct a custom calculation script in a PDF form that is returning a 'NaN' (Not a Number) error.

How to Fix a NaN Error in PDF Form Calculation Scripts
Product
Adobe Acrobat / PDF Forms
Device & OS
not provided
Scenario
Creating or editing interactive PDF forms using custom JavaScript to automatically calculate totals, such as monthly or quarterly dues.
Observed behavior
The calculation output displays a 'NaN' error because the JavaScript is incorrectly referencing field names as text strings instead of retrieving their actual numerical input values.
Before you start

Open your interactive PDF form in editing mode and note the exact spelling and capitalization of the fields you want to calculate, as JavaScript field referencing is strictly case-sensitive.

Solution 1Recommended

Update the JavaScript Field References

Fix the NaN error by modifying the script to fetch numeric values using the getField() method instead of treating field names as text literals.

The 'NaN' (Not a Number) error occurs in JavaScript when mathematical operations are attempted on text strings.

By wrapping your field references in the Number() function and properly targeting the field's value, you ensure the script retrieves the actual numerical input rather than the plain text of the field name itself.

1
Access field properties

Right-click the specific form field that is returning the NaN error and select 'Properties' from the context menu.

2
Open the custom script editor

Navigate to the 'Calculate' tab in the Properties window, choose the 'Custom calculation script' option, and click the 'Edit' button.

3
Fetch numeric values properly

Update your script variables to pull the actual values using the getField() method. For example: var amountDue = Number(this.getField("amount due").value); and var term = Number(this.getField("term").value);

4
Apply calculation logic

Write your conditional logic using the newly defined numerical variables. For example, to calculate monthly totals: if (frequency == "monthly") { event.value = amountDue * term; }

5
Save and verify

Click 'OK' to save the updated calculation script and close the Properties window. Test the form by entering numbers into the source fields to confirm the NaN error is resolved.

Update the JavaScript Field References
Retrieving Text Dropdown Values: If you are retrieving a text condition from a dropdown field (like 'monthly' or 'quarterly'), use this.getField("fieldname").valueAsString instead of the Number() wrapper.
Advanced PDF Form Editing

Create and Calculate PDF Forms Seamlessly with WPS Office

WPS Office provides a powerful, user-friendly PDF editor that allows you to easily create interactive forms, add text fields, and manage document calculations without struggling with complex scripting errors.

  1. 1. Open your PDF: Launch WPS Office and open your existing PDF document or create a new one from a template.
  2. 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to access interactive tools like text fields, checkboxes, and combo boxes.
  3. 3. Set field properties: Double-click any added form field to open its properties, where you can assign names, format values, and set up calculations easily.
  4. 4. Save and share: Once your form is set up and calculating correctly, save the PDF and share it with others for secure data collection.
Easily insert and manage interactive PDF form fields, checkboxes, and dropdowns.High compatibility with standard PDF calculation scripts and Microsoft Office formats.Intuitive user interface for designing, editing, and protecting professional documents.Lightweight application that opens large interactive PDFs instantly.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF form show NaN when the input fields are left blank?

When source fields are empty, JavaScript may evaluate them as undefined or non-numeric text, triggering a NaN result. You can avoid this by adding an 'if' statement in your script to check whether the field value is empty before performing the calculation.

Are PDF calculation field names case-sensitive in JavaScript?

Yes, JavaScript is strictly case-sensitive. The field names referenced in this.getField("FieldName") must exactly match the name of the form field, including spaces and capitalization, or the script will fail.

Can I perform PDF calculations without writing JavaScript code?

Yes, for simple mathematical operations like addition or multiplication, you can use the built-in simplified field notation. In the Calculate tab of the field properties, select 'Value is the [sum/product] of the following fields' and pick your target fields to avoid manual coding.