Show a Comment Field After Adding an Image in an Acrobat Form
Question details
Show a comment field when an image is imported into a PDF form button, and hide and clear it when no image is present.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A form user imports an image into a button and can then enter an associated comment.
- Observed behavior
- The desired form shows the comment field after an image is added and hides and clears it when the image is removed.
Open the PDF in Adobe Acrobat and confirm that it contains an image button and a text field for the comment. Note the text field's exact name and make sure JavaScript is enabled for testing.
Add JavaScript to the Acrobat Image Button
Use the button's Mouse Up action to show the comment field after a successful image import and hide and clear it if the import does not succeed.
In Adobe Acrobat, open the PDF and choose Prepare a form. Create a button and a text field if the form does not already have them.
Double-click the comment text field to open Properties. On the General tab, note its exact Name and set Form Field to Hidden if it should initially be hidden.
Double-click the image button, open the Actions tab, and select Mouse Up as the trigger. Choose Run a JavaScript as the action, then click Add.
In the JavaScript editor, enter the following code. Replace ImageComment with the exact name of your text field: if (event.target.buttonImportIcon() == 0) { this.getField("ImageComment").display = display.visible; } else { this.getField("ImageComment").display = display.hidden; this.getField("ImageComment").value = ""; }
Save the PDF, exit form editing, and click the image button to import an image. Confirm that a successful import shows the comment field; also test canceling the import to check the hide-and-clear behavior.

Work With PDF Forms and Office Files in WPS Office
WPS Office is a free, lightweight alternative for everyday document work, with a familiar interface and support for Microsoft Office formats to help you move existing files. For the Acrobat-specific form JavaScript in this article, use Adobe Acrobat.

Frequently Asked Questions
What should I replace ImageComment with in the script?
In Prepare a form, double-click the comment text field and check its Name on the General tab. Replace ImageComment in the script with that exact field name.
Why does canceling the image import clear the comment?
The script treats any result other than 0 as an unsuccessful import. Its else branch hides the comment field and sets its value to an empty string, including when the import is canceled.
Will this script clear the comment when an image is removed elsewhere in the form?
No. The script runs only from the image button's Mouse Up action. Add hide-and-clear logic to any separate control used to remove the image.
Why might the form not work in every PDF viewer?
The button uses Acrobat JavaScript and buttonImportIcon. Other PDF viewers may not support the same form actions, and Adobe Reader behavior can depend on document permissions. Test the saved form in the viewer your recipients will use.




