PDF Editing Issues

Show a Comment Field After Adding an Image in an Acrobat Form

Camila MilosovichCamila Milosovich Nov 19, 2026 868 views

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.

Show a Comment Field After Adding an Image in an Acrobat Form
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

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.

2
Check the comment field name

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.

3
Add the button action

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.

4
Enter the script

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 = ""; }

5
Save and test the form

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.

Add JavaScript to the Acrobat Image Button
Image removal requires a separate action: This script runs when the image button is clicked. An unsuccessful or canceled import hides and clears the comment, but the script does not itself remove an existing image or detect removal by another action. If your form has a separate image-removal control, configure that control to hide and clear the comment field as well.
Free Microsoft Office alternative

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.

Open and review PDF documents alongside your other files.Compatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTX.Use a familiar interface for everyday office tasks.Move existing Office files into a lightweight all-in-one workspace.
microsoft office alternative - wps office

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.