Fix NaN Error in PDF Form Calculation Scripts
Question details
The user needs to correct a custom calculation script in a PDF form that is returning a 'NaN' (Not a Number) error.

- 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.
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.
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.
Right-click the specific form field that is returning the NaN error and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties window, choose the 'Custom calculation script' option, and click the 'Edit' button.
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);
Write your conditional logic using the newly defined numerical variables. For example, to calculate monthly totals: if (frequency == "monthly") { event.value = amountDue * term; }
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.

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. Open your PDF: Launch WPS Office and open your existing PDF document or create a new one from a template.
- 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. 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. Save and share: Once your form is set up and calculating correctly, save the PDF and share it with others for secure data collection.

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.




