PDF Editing Issues

Create PDF Form Buttons to Show or Hide Field Groups in Acrobat

Jason MillerJason Miller Nov 24, 2026 868 views

Question details

Create buttons that reveal groups of three number fields and hide individual groups in a PDF form.

Create PDF Form Buttons to Show or Hide Field Groups in Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A form needs an Add Numbers button and an X button for each group of three fields.
Observed behavior
Each Add Numbers click should reveal one group, and its X button should hide that group.
Before you start

Open the PDF in a desktop version of Adobe Acrobat with Prepare a Form available. Decide how many groups you need and reserve space for them on the page; this example uses three groups.

Solution 1Recommended

Use Acrobat JavaScript to Show and Hide Pre-Created Field Groups

Create the fields in advance, then use button actions to reveal or hide each group.

Standard Acrobat forms do not automatically reflow page content when fields appear or disappear. The groups remain in their fixed positions, so hiding a group can leave a blank space.

1
Create the number fields

In Acrobat, open All tools > Prepare a form. Add three text fields for each group and name them n1_1, n1_2, n1_3; n2_1, n2_2, n2_3; and n3_1, n3_2, n3_3. In each field's Properties, use the Format tab to select Number if you want numeric formatting.

2
Create the remove buttons

In Prepare a form, add an X button beside each group. Name the buttons rm_1, rm_2, and rm_3, respectively, and set their visible labels to X.

3
Hide the groups initially

Open Properties for each number field and X button. On the General tab, set Form Field to Hidden so all three groups start out hidden.

4
Add the reveal action

Add a button labeled Add Numbers. In its Properties > Actions, select Mouse Up and Run a JavaScript, click Add, and enter: for (var i = 1; i <= 3; i++) { if (this.getField('n' + i + '_1').display === display.hidden) { for (var j = 1; j <= 3; j++) this.getField('n' + i + '_' + j).display = display.visible; this.getField('rm_' + i).display = display.visible; break; } }

5
Add the hide actions

For each X button, open Properties > Actions, select Mouse Up and Run a JavaScript, click Add, and enter the same script: var i = event.target.name.split('_')[1]; for (var j = 1; j <= 3; j++) this.getField('n' + i + '_' + j).display = display.hidden; event.target.display = display.hidden;

6
Test the form

Use Preview in Prepare a form. Click Add Numbers repeatedly, click an X to hide a group, and click Add Numbers again to reveal the first hidden group. Save the PDF after testing.

Use Acrobat JavaScript to Show and Hide Pre-Created Field Groups
Field values are retained: Hiding a group does not clear its values. The scripts support three pre-created groups; to use more, create and name the additional fields and buttons and change the reveal script's loop limit.
Free Microsoft Office alternative

Work With PDFs and Office Files in WPS Office

WPS Office is a free, lightweight alternative for everyday document work, with a familiar interface and support for common Microsoft Office formats. It can help you move between Office files and PDFs, but it does not replace Acrobat's form-button scripting workflow.

Open and review PDF documents alongside your office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface makes it easier to move from Microsoft OfficeFree, lightweight tools for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

Will the PDF form move content up when I hide a group?

No. Standard Acrobat form fields have fixed positions, so hiding a group can leave blank space. Plan the page layout around the maximum number of groups.

What happens when all three groups are visible?

The example Add Numbers script does nothing until a group is hidden. To support more groups, add the fields and X buttons in Prepare a form and increase the script's loop limit.

Does clicking X erase the numbers in that group?

No. The example X action only hides the fields and button. The values remain if the group is revealed again.

Why don't the buttons work in every PDF viewer?

The buttons use Acrobat JavaScript, which some PDF viewers do not support or may have disabled. Test the saved form in Acrobat or a viewer that supports the required JavaScript actions.