PDF Editing Issues

Fix an Acrobat Form JavaScript Error When Dividing by a Field

Adam DavisAdam Davis Nov 19, 2026 869 views

Question details

Correct an Acrobat form calculation that multiplies one field by 200,000 and divides it by another, returning NA when the divisor is blank or zero.

Fix an Acrobat Form JavaScript Error When Dividing by a Field
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form uses a custom JavaScript calculation to divide the value of LogTot1 by Hours1 after applying a multiplier.
Observed behavior
The script reports a syntax error because it attempts to declare a variable inside the if condition.
Before you start

Open the PDF in Acrobat and confirm that the source fields are named LogTot1 and Hours1. Identify the result field where the custom calculation script is stored.

Solution 1Recommended

Correct the custom calculation script in Acrobat

Declare the field variables before the condition and assign NA when the divisor is blank or zero.

1
Open the result field

In Acrobat, open the PDF and select Prepare a Form. Double-click the field that should display the calculation result.

2
Edit the calculation script

In the field properties, select Calculate, choose Custom calculation script, and click Edit.

3
Replace the script

Enter this script, adjusting the field names if necessary: var nA = Number(this.getField("LogTot1").valueAsString); var nB = Number(this.getField("Hours1").valueAsString); if (nB === 0) { event.value = "NA"; } else { event.value = (nA * 200000) / nB; }

4
Save and test the form

Click OK to save the script, close the field properties, and exit form editing. Enter values in LogTot1 and Hours1, then test Hours1 as blank and as zero; both should display NA.

Correct the custom calculation script in Acrobat
Check field formatting: A blank Hours1 value converts to zero with Number(). If the result field has a numeric-only format, change its Format setting as needed so it can display the text NA.
Free Microsoft Office alternative

Work with PDF and Office files in WPS Office

WPS Office is a free, lightweight alternative for everyday document work, with a familiar interface and Microsoft Office format compatibility to make moving existing files easier. Use it to view and work with PDFs, although it does not fix Acrobat's form JavaScript.

View PDF documents alongside your other office filesOpen and edit common Microsoft Word, Excel, and PowerPoint formatsNavigate a familiar interface for easier migrationUse a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does declaring a variable inside the if condition cause an error?

An if condition must contain an expression, not a var declaration. Declare nB before the if statement, then test its value inside the parentheses.

Why does the script check only whether nB is zero?

Number() converts both a blank field value and a numeric zero to 0. The condition nB === 0 therefore covers both cases.

Where do I find the custom calculation script?

In Acrobat, select Prepare a Form, open the result field's properties, and go to Calculate. Select Custom calculation script and click Edit.

What if NA does not display in the result field?

Open the result field's properties and check the Format tab. A numeric-only format may prevent the text NA from displaying correctly.