PDF Editing Issues

How to Create a Document-Level Show and Hide Function in Acrobat JavaScript

Olivia MillerOlivia Miller Nov 5, 2026 870 views

Question details

The user needs to write a reusable document-level JavaScript function in Adobe Acrobat to toggle the visibility of a PDF field using a checkbox.

How to Create a Document-Level Show and Hide Function in Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating interactive PDF forms where specific text fields appear or disappear dynamically when a user interacts with a checkbox.
Observed behavior
A script is required that cleanly shows or hides target fields based on the selected state of a checkbox, avoiding repetitive code by utilizing a central document-level function.
Before you start

Ensure you have Adobe Acrobat Pro or an equivalent advanced PDF editor that supports document-level JavaScript execution and interactive form field editing.

Solution 1Recommended

Implementing Document-Level Show/Hide JavaScript in Acrobat

Add a central function to your PDF's document-level scripts, then trigger it from the Mouse Up actions of individual checkboxes.

By placing the script at the document level, you create a reusable function. This prevents you from having to rewrite the visibility logic for every single checkbox in a complex PDF form.

1
Open the Document JavaScripts dialog

In Adobe Acrobat, go to the 'Tools' menu and select 'Prepare Form'. From the right-hand panel or top toolbar, find the 'More' options (or the JavaScript panel) and select 'Document JavaScripts'.

2
Add the reusable function

Type a script name (e.g., 'showHideScript') and click 'Add'. Delete any default code in the editor and paste the following function: function showHide(fieldPeek) { this.getField(fieldPeek).display = event.target.isBoxChecked(0) ? display.visible : display.hidden; }

3
Configure the checkbox trigger

Right-click the checkbox you want to use as a trigger in your form and select 'Properties'. Navigate to the 'Actions' tab.

4
Set the Mouse Up action

Choose 'Mouse Up' from the Select Trigger dropdown menu, and select 'Run a JavaScript' from the Select Action dropdown. Click 'Add'.

5
Call the function

In the JavaScript Editor, enter the function call: showHide("A1.Text.0"); replacing 'A1.Text.0' with the actual name of the text field you want to toggle. Click 'OK' and close the properties window.

Implementing Document-Level Show/Hide JavaScript in Acrobat
Syntax Check: When calling the script in the Mouse Up action, make sure you do not include the 'function' keyword. Only use quotes around the target string value.
Powerful PDF Editor

Create and Manage Interactive PDFs with WPS Office

WPS Office includes a comprehensive PDF editor that allows you to view, edit, and interact with PDF forms easily. Manage your document workflows seamlessly without switching between multiple heavy applications.

  1. 1. Open your PDF in WPS Office: Launch WPS Office and open your interactive PDF file using the built-in WPS PDF tool.
  2. 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to view available interactive field tools and highlights.
  3. 3. Interact with form fields: Easily click on checkboxes, dropdowns, and text fields to test their interactive behaviors and fill out the form.
  4. 4. Save and export: Once your form is filled or tested, save the document or export it to ensure it retains its interactive elements perfectly.
Easily view and interact with PDF form fields, checkboxes, and text inputs.Lightweight and fast PDF processing, even for large, complex documents.Fully compatible with standard PDF formats and interactive form structures.Edit text, images, and pages directly within your PDF files seamlessly.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF text field not hiding when the checkbox is unchecked?

Ensure the field name passed in the showHide function matches exactly with the target field's name in the PDF, including case sensitivity. Also, verify that the trigger is set to 'Mouse Up' rather than 'Mouse Down' so it registers the click completely.

Can I use this JavaScript function to hide multiple fields at once?

Yes, you can modify the document-level script to accept an array of field names and loop through them, setting the display property to visible or hidden for each field in the array simultaneously.

Where do I find Document JavaScripts in newer versions of Adobe Acrobat?

In recent versions of Acrobat Pro, you can find Document JavaScripts by searching for 'JavaScript' in the Tools menu, selecting the 'JavaScript' tool, and then clicking 'Document JavaScripts' in the secondary toolbar.

Do I need programming experience to add this script?

While basic JavaScript knowledge is helpful, you do not need to be a programmer. You can simply copy and paste the provided code snippet into the Document JavaScripts window and just customize the target field name inside the quotes when setting up the checkbox.