Show or Hide an Adobe Acrobat PDF Text Field When an Icon Changes
Question details
Control a PDF form text field based on whether an image has been imported into a button icon.

- 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.
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.
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.
In All tools > Prepare a form, open the image button's Properties, select Actions, and choose Mouse Up and Run a JavaScript.
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;
Open the JavaScript action that removes the icon. Immediately after its existing removal code succeeds, add: this.getField("TextField").display = display.visible;
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.

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.

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.




