How to Fix Acrobat JavaScript NaN Error for Height Fields with Apostrophes
Question details
The user needs to prevent a custom Acrobat JavaScript calculation from returning a NaN (Not a Number) error when a height field contains apostrophes and quotation marks (e.g., 6'6").

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Performing automated math calculations on a user-input height field formatted with feet and inches (using ' and ") in a PDF form.
- Observed behavior
- The custom calculation script returns a NaN error because standard mathematical operations fail when they encounter non-numeric characters like apostrophes and quotes.
Ensure your PDF form is opened in Prepare Form mode and that you have basic familiarity with editing Document JavaScripts in your PDF editor.
Parse and Split the Height String to Extract Numeric Values
Use JavaScript's string manipulation methods to isolate the numeric part of the feet value before performing calculations.
When a user inputs a height like 6'6", JavaScript treats the entire entry as a text string rather than a number. Attempting to divide or multiply this directly results in a NaN error. By forcing the field value to be read as a string and splitting it at the apostrophe, you can extract just the feet portion as a usable number.
Open your PDF file and access the 'Prepare Form' tool from the right-hand pane to view all editable form fields.
Right-click on the specific target field where the calculation result should appear and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab, select the 'Custom calculation script' option, and click the 'Edit' button.
Type the following script to read the field as a string and extract the feet: var HT = Number(this.getField("Height").valueAsString.split("'")[0]);
Add your calculation logic on the next line (for example, to halve the value): event.value = Math.round(HT / 2);
Save your script and exit Prepare Form mode. Enter a value like 6'6" in the Height field to verify the NaN error is resolved.

Create and Manage Interactive PDF Forms with WPS PDF
WPS Office provides a comprehensive and easy-to-use PDF toolset that allows you to create interactive forms, edit text, and manage PDF documents without needing complex programming or expensive software.
- 1. Launch WPS PDF: Open WPS Office and click on the 'PDF' tab on the home screen to access the dedicated PDF editor.
- 2. Open your document: Load the PDF document you wish to transform into an interactive form.
- 3. Navigate to the Form tab: Click on the 'Form' tab in the top ribbon to reveal various interactive form controls.
- 4. Add form fields: Select text fields, checkboxes, or dropdown menus and place them anywhere on your document to quickly build your interactive PDF.

Frequently Asked Questions
Why does JavaScript return NaN for height values like 6'6"?
NaN stands for 'Not a Number'. JavaScript interprets the apostrophe (') and quote marks (") as non-numeric string characters. When standard mathematical operations attempt to process a string containing these symbols, the calculation fails and returns a NaN error.
How can I calculate total inches from a feet-and-inches string?
You need to split the string twice within your script. First, split by the apostrophe to get the feet, and then split the remaining portion by the quote mark to isolate the inches. Finally, multiply the extracted feet value by 12 and add the extracted inches.
Does valueAsString work on all PDF form fields?
Yes, in standard PDF JavaScript environments, the valueAsString property forces the field's content to be read strictly as a text string, bypassing the default formatting. This is essential when you need to parse custom numerical formats containing symbols.
How do I output the calculated mathematical result back into the X'Y" format?
After completing your mathematical operations on the extracted numbers, use string concatenation to rebuild the visual format. Set your final event value like this: event.value = calculatedFeet + "'" + calculatedInches + "\"";




