How to Prevent NaN:NaN Errors in Acrobat PDF Time Calculations
Question details
The user needs to prevent a custom JavaScript time calculation in a PDF from displaying NaN:NaN when the input fields are left blank.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating custom JavaScript calculations for takeoff and landing times in a PDF form.
- Observed behavior
- The calculated field displays 'NaN:NaN' when the input time fields are empty, instead of remaining blank.
Ensure you have access to edit the PDF form fields and are familiar with basic JavaScript scripting within PDF form properties.
Add an Empty Field Check in the JavaScript Calculation
Modify the calculation script to verify that the input fields contain data before attempting to parse and calculate the time differences.
The 'NaN:NaN' error occurs because JavaScript tries to perform mathematical operations on an undefined or empty string value. By explicitly instructing the script to only execute the time calculation when both the takeoff and landing fields have values, you eliminate the error.
In your PDF editor's form preparation mode, right-click the calculated flight-time field and select 'Properties'.
Navigate to the 'Calculate' tab within the Properties window and select the 'Custom calculation script' option.
Click the 'Edit' button and wrap your existing calculation logic inside a conditional statement that checks if the input fields are blank. For example: `if (this.getField('takeoff').valueAsString !== '' && this.getField('landing').valueAsString !== '') { // your calculation }`.
Add an `else` block to clear the output if the fields are empty by assigning an empty string to the event value: `else { event.value = ''; }`.

Edit and Fill Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that lets you easily fill, edit, and manage interactive PDF forms securely. Enjoy a highly compatible and clean interface for all your document tasks.
- 1. Open the PDF: Launch WPS Office and open your interactive PDF form document.
- 2. Navigate to the Form Tab: Click on the 'Form' tab in the top ribbon to access robust form-filling and editing features.
- 3. Fill Form Fields: Click directly into the text fields, such as time entry fields, to input your data safely.
- 4. Save the Document: Click the 'Save' icon in the top left corner to ensure your filled form data is securely stored in the PDF.

Frequently Asked Questions
What does NaN mean in a PDF calculation?
NaN stands for 'Not a Number'. It appears when the JavaScript in a PDF form attempts a mathematical operation on an invalid, empty, or non-numerical value.
How do I access custom calculation scripts in a PDF form?
Open the form editing or preparation mode, right-click the specific form field you want to calculate, choose 'Properties', go to the 'Calculate' tab, and select 'Custom calculation script'.
Can I use time formats like HH:MM directly in PDF math calculations?
No, standard mathematical operations cannot be applied directly to an HH:MM string. You must first use JavaScript to split the string and parse the hours and minutes into numerical values before performing calculations.




