PDF Editing Issues

Fix Acrobat JavaScript If-Else Syntax and Form Calculation Errors

Rana GarciaRana Garcia Nov 2, 2026 869 views

Question details

The user needs to correct a custom calculation script in a PDF form to accurately return conditional values, set minimum and maximum limits, and handle zero inputs by returning a blank value.

How to Fix Acrobat JavaScript If-Else Syntax and Form Calculation Errors
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Setting up a custom calculation script in a PDF form to dynamically adjust field values based on specific conditions.
Observed behavior
The target calculation field currently produces no output despite having conditions set for minimum, maximum, and intermediate calculations.
Before you start

Ensure that JavaScript is enabled in your PDF viewer preferences and verify that the field names referenced in your script (e.g., 'Text9') exactly match the names in your form.

Solution 1Recommended

Use validated JavaScript syntax with event.value

Update your custom calculation script to properly validate input numbers and assign the output directly to the event.value property.

Acrobat form calculations require rigorous handling of empty or non-numeric fields. By converting the field value to a number and checking for NaN (Not a Number), you can prevent silent script failures.

1
Enter Prepare Form mode

Open Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form' to enable form editing.

2
Access field properties

Right-click the calculation field that is failing to produce output and select 'Properties' from the context menu.

3
Edit custom calculation script

Go to the 'Calculate' tab, select 'Custom calculation script', and click the 'Edit' button.

4
Insert the corrected script

Enter the following code: var v1 = Number(this.getField("Text9").valueAsString); if (isNaN(v1) || v1 === 0) event.value = ""; else if (v1 < 100) event.value = 200; else if (v1 <= 150) event.value = v1 + 100; else event.value = 250;

5
Save and test

Click 'OK', close the properties window, and test the form by entering a numeric value into the source field (Text9).

Use validated JavaScript syntax with event.value
Syntax check: Using 'valueAsString' ensures that empty fields do not cause unexpected calculation errors when evaluated.
Powerful PDF Editor & Form Filler

View and Manage Interactive PDF Forms with WPS Office

While creating complex JavaScript calculation forms often requires advanced authoring tools, WPS Office provides a lightweight, seamless experience for viewing, filling, and managing interactive PDF forms.

  1. 1. Download and Install: Download and install WPS Office from the official website onto your computer.
  2. 2. Open PDF Form: Launch WPS PDF and open your interactive PDF document containing the form fields.
  3. 3. Fill the Fields: Click on the form fields to input your data. Calculation fields will automatically update based on the document's built-in rules.
  4. 4. Save and Export: Once completed, click 'Save' to securely store your filled-out PDF form or share it directly.
Seamlessly fill out interactive PDF forms containing built-in calculationsHighly compatible with standard Adobe PDF formatsEdit PDF text, insert images, and add electronic signatures effortlesslyLightweight application that performs efficiently without slowing down your device
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF form calculation script producing no output?

This usually happens if JavaScript is disabled in your PDF viewer, the script contains syntax errors (like missing braces), or the field names referenced in the code do not perfectly match the actual form field names.

How do I leave a PDF calculation field blank if the value is zero?

You can achieve this by adding a conditional check in your JavaScript code, such as 'if (v1 === 0) { event.value = ""; }', which explicitly sets the calculation field's value to an empty string.

Should I use event.value or event.target.value in Acrobat?

In Acrobat custom calculation scripts, it is standard practice to assign the result directly to 'event.value'. Using 'event.target.value' can also work in some contexts, but 'event.value' is generally preferred for calculating the active field.