Fix Acrobat JavaScript Form Calculation Errors
Question details
Correct JavaScript calculations that use dropdown and text field values in an Acrobat PDF form.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form uses JavaScript to calculate a result from dropdown and text fields.
- Observed behavior
- The calculated field displays NaN, [object Field]0, or an unexpected zero.
Open the PDF in Acrobat and choose Prepare a form. Identify the exact names of the input and calculated fields, and check whether dropdown options have numeric export values.
Read and convert field values in the calculation script
Use this approach when the script treats field objects as values or receives empty or nonnumeric input.
getField returns a field object, not its entered value. Use its .value property and convert numeric input before calculating; otherwise, concatenation can produce text such as [object Field]0.
In Prepare a form, open the calculated field's Properties, select the Calculate tab, and choose Custom calculation script > Edit.
Replace field names as needed and adapt this example to your formula: (function () { var a = this.getField('level1'); var b = this.getField('level2'); if (!a || !b) { event.value = ''; return; } var x = String(a.value).trim(); var y = String(b.value).trim(); if (x === '' || y === '') { event.value = ''; return; } var n1 = Number(x); var n2 = Number(y); if (!isFinite(n1) || !isFinite(n2)) { event.value = ''; return; } event.value = Math.floor(n1 + n2); }).call(this);
In Prepare a form, open the dropdown field's Properties and check the Options tab. Ensure each option used in the calculation has a numeric export value, or update the script to map text choices to numbers.
Save the script, close the field properties, and test the form with numeric, empty, and nonnumeric inputs. If the inputs are calculated fields, use Prepare a form > More > Set Field Calculation Order to place them before the result field.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Open common file formats to make migration easier, but use Acrobat to troubleshoot its JavaScript form calculations.

Frequently Asked Questions
Why does my calculated field show [object Field]0?
The script is likely combining a field object with another value. In the calculated field's custom calculation script, use the object's .value property and convert it with Number() when the calculation needs a number.
What causes NaN in an Acrobat calculation?
NaN can appear when a value cannot be converted to a number. Check the input fields and dropdown export values, then validate converted values before assigning the result to event.value.
Why does my calculation return zero for an empty field?
Number('') returns 0. Check whether each field value is empty before conversion, and set event.value to an empty string if the calculation should wait for input.
How do I change the order of calculated fields?
In Acrobat's Prepare a form tool, choose More > Set Field Calculation Order. Place fields that supply calculated values before fields that depend on them.




