PDF Editing Issues

How to Show or Hide a PDF Form Field Using JavaScript Based on Another Field

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 869 views

Question details

The user wants to use JavaScript to conditionally display a PDF form field only when another specific field contains a value.

How to Show or Hide a PDF Form Field Using JavaScript Based on Another Field
Product
Adobe Acrobat / LiveCycle Designer
Device & OS
not provided
Scenario
Creating interactive PDF forms where target fields appear or disappear dynamically based on the input data of a controlling field.
Observed behavior
The target field needs to toggle visibility based on whether the controlling field has a non-null, non-empty value, but the correct script depends on the form creation tool used.
Before you start

Determine whether your PDF form was created in Adobe Acrobat (AcroForm) or Adobe LiveCycle Designer (XFA form), as the JavaScript syntax and document object models differ significantly between the two.

Solution 1Recommended

Use JavaScript to Control Field Visibility in Standard Acrobat Forms

Apply a custom JavaScript calculation or validation script to check for empty strings and toggle the target field's display property in standard AcroForms.

Standard PDF forms created in Adobe Acrobat use the Acrobat JavaScript API. To control visibility, you can use the 'display.visible' or 'display.hidden' properties. It is crucial to check for an empty string instead of just a null value, as empty fields in Acrobat usually return an empty string.

1
Enter form editing mode

Open your PDF in Acrobat, go to the 'Tools' menu, and select 'Prepare Form' to enter editing mode.

2
Access field properties

Right-click the controlling field (the field the user types into) and select 'Properties'.

3
Add a custom calculation script

Navigate to the 'Calculate' or 'Validate' tab, select 'Custom calculation script', and click 'Edit'.

4
Input the JavaScript code

Enter the script to check the value and set visibility. For example: `if (event.value !== '') { this.getField('TargetFieldName').display = display.visible; } else { this.getField('TargetFieldName').display = display.hidden; }`.

Use JavaScript to Control Field Visibility in Standard Acrobat Forms
Empty String Check: Always test the controlling field value with an empty-string check (event.value !== '') rather than only testing for null to ensure reliable visibility toggling.
Free Microsoft Office alternative

Manage and Edit PDF Documents Easily with WPS Office

While advanced JavaScript for XFA forms requires specialized software, WPS Office provides a comprehensive, lightweight, and free alternative for standard PDF viewing, editing, and form filling. It is fully compatible with mainstream document formats and offers an intuitive interface.

  1. 1. Download and Install: Get WPS Office for free from the official website and install it on your device.
  2. 2. Open your PDF: Launch WPS Office and open your interactive PDF form.
  3. 3. Fill and Save: Easily click on form fields to fill in your data, then save or export your completed document.
Easily fill out, save, and print standard interactive PDF forms.Fully compatible with Microsoft Office formats and standard PDF documents.Lightweight software with a familiar, user-friendly interface.Edit PDF text, images, and pages without expensive subscriptions.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my target field hiding when the controlling field is empty?

Ensure your JavaScript checks for an empty string ("") rather than just a null value. In Acrobat, an empty text field usually returns an empty string, so a strict null check will fail to hide the target field.

What is the difference between AcroForms and XFA forms?

AcroForms are standard PDF forms created directly in Adobe Acrobat, utilizing the Acrobat JavaScript API (using properties like display.hidden). XFA forms are XML-based forms created in LiveCycle Designer, which require a different scripting approach (using properties like presence = 'hidden').

Will this JavaScript work on mobile PDF viewers?

Advanced JavaScript form validations and calculations may not be supported on all mobile PDF viewer apps. It is highly recommended to test your interactive forms thoroughly across the specific devices and applications your users will utilize.