PDF Editing Issues

Show or Hide an Adobe Acrobat PDF Text Field When an Icon Changes

Huda QurayshiHuda Qurayshi Nov 25, 2026 868 views

Question details

Control a PDF form text field based on whether an image has been imported into a button icon.

Show or Hide a PDF Text Field When an Icon Changes in Adobe Acrobat
Product
Adobe Acrobat PDF forms
Device & OS
not provided
Scenario
A form user imports an image as a button icon or removes the existing image.
Observed behavior
The text field should be hidden while an icon is present and visible again after the icon is removed.
Before you start

Open the form in Adobe Acrobat and use All tools > Prepare a form to check the names of the image button and text field. The example assumes the button's normal face starts without a default icon and that JavaScript is enabled.

Solution 1Recommended

Update the text field after importing or removing the icon

Use Acrobat JavaScript in the form's existing import and removal actions to keep the text field synchronized with the image.

The example checks the button's normal icon face, not the image filename, so it works regardless of which supported image is imported. Replace ImageButton and TextField with your actual field names.

An import button action alone cannot detect an icon removed by a separate action. Add the visibility update to that removal action as well.

1
Open the button action

In All tools > Prepare a form, open the image button's Properties, select Actions, and choose Mouse Up and Run a JavaScript.

2
Add the import script

In the JavaScript editor, use the following script for the image button: var btn = this.getField("ImageButton"); btn.buttonImportIcon(); var icon = btn.buttonGetIcon(0); this.getField("TextField").display = icon ? display.hidden : display.visible;

3
Update the removal action

Open the JavaScript action that removes the icon. Immediately after its existing removal code succeeds, add: this.getField("TextField").display = display.visible;

4
Test the form

Save the PDF and exit form editing. Use the image button to import an icon, then use your existing removal control to remove it; confirm that the text field hides and reappears.

Update the text field after importing or removing the icon
Viewer support: Test in Acrobat or a PDF viewer that supports the required Acrobat JavaScript methods. Browser PDF viewers may not run these form actions.
Free Microsoft Office alternative

Work with PDF and Office files in WPS Office

WPS Office is a free, lightweight alternative for everyday PDF and document work. Its familiar interface and Office format compatibility make it easy to move existing files into your workflow. Use Acrobat for the icon-driven JavaScript form behavior described above.

Open and review PDF forms alongside other documentsCompatible with Microsoft Office formats such as DOCX, XLSX, and PPTXFamiliar interface for a smooth transition from Microsoft OfficeFree, lightweight tools for everyday office work
microsoft office alternative - wps office

Frequently Asked Questions

How does the script know whether an icon is present?

The import action calls buttonGetIcon(0) on the image button to check its normal face. It hides the text field when an icon is returned and shows it otherwise.

Will removing an icon automatically show the text field?

Not with the import action alone. In Prepare a form, open the separate icon-removal action and set the text field's display property to display.visible after removal succeeds.

What happens if the image button has a default icon?

The example treats any icon on the normal face as present, including a default or placeholder icon. Start with that face empty or adapt the form's logic to distinguish its initial state.

Why does the form work in Acrobat but not in a browser?

Some browser PDF viewers do not support Acrobat JavaScript or button icon methods. Open and test the saved form in Acrobat or another viewer that supports the required methods.