PDF Editing Issues

How to Prevent NaN:NaN Errors in Acrobat PDF Time Calculations

Camila MilosovichCamila Milosovich Nov 5, 2026 869 views

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.

How to Prevent NaN:NaN Errors in Acrobat PDF Time Calculations
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.
Before you start

Ensure you have access to edit the PDF form fields and are familiar with basic JavaScript scripting within PDF form properties.

Solution 1Recommended

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.

1
Open Field Properties

In your PDF editor's form preparation mode, right-click the calculated flight-time field and select 'Properties'.

2
Access the Calculate Tab

Navigate to the 'Calculate' tab within the Properties window and select the 'Custom calculation script' option.

3
Edit the Script

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 }`.

4
Set Empty Default Value

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 = ''; }`.

Add an Empty Field Check in the JavaScript Calculation
Using event.value: Always assign the final calculated result to `event.value` in a PDF custom calculation script to ensure the target field updates properly on the form.
Manage PDF Forms Easily

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. 1. Open the PDF: Launch WPS Office and open your interactive PDF form document.
  2. 2. Navigate to the Form Tab: Click on the 'Form' tab in the top ribbon to access robust form-filling and editing features.
  3. 3. Fill Form Fields: Click directly into the text fields, such as time entry fields, to input your data safely.
  4. 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.
Easily fill, edit, and manage interactive PDF form fields securelyHigh compatibility with standard PDF formats and Adobe Acrobat formsLightweight application that handles PDFs, Word, Excel, and PPT files seamlessly
microsoft office alternative - wps office

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.