PDF Editing Issues

Use Acrobat JavaScript for PDF Form Buttons and Fields

Emma BrownEmma Brown Nov 24, 2026 868 views

Question details

Learn how to use Acrobat JavaScript to control PDF form fields, calculate values, and validate entries.

Use Acrobat JavaScript for PDF Form Buttons and Fields
Product
Adobe Acrobat
Device & OS
not provided
Scenario
The user is building an interactive PDF form with buttons, calculated totals, and percentage limits.
Observed behavior
The form should respond to button actions, calculate values, and alert users when entries are outside the allowed range.
Before you start

Open the PDF in Adobe Acrobat and confirm that the Prepare a Form tool is available. Plan the field names and check whether the PDF viewer used by recipients supports Acrobat JavaScript.

Solution 1Recommended

Use button actions to control PDF form fields

Create named fields and assign button scripts to show, hide, add, or remove fields.

1
Create and name the fields

Open All tools > Prepare a form, add a text field and a button, and name the text field Details in its Properties dialog. Field names in scripts must match exactly.

2
Add a button action

Open the button's Properties > Actions, select Mouse Up as the trigger and Run a JavaScript as the action, then click Add.

3
Show or hide a field

In the JavaScript editor, enter `this.getField("Details").display = display.hidden;` to hide the field. Use `display.visible` instead to show it. Save the action and test the button in Preview.

4
Add or remove a field

For a separate button action, use `this.addField("Extra", "text", 0, [72, 720, 200, 700]);` to add a text field on the first page. Adjust the rectangle coordinates for the page. To remove it, use `if (this.getField("Extra")) this.removeField("Extra");`.

Use button actions to control PDF form fields
Test viewer support: JavaScript support and permissions vary by PDF viewer. Adding or removing fields may be restricted, so test these actions in the viewer recipients will use.
Free Microsoft Office alternative

Work with PDF forms and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Microsoft Office files. Its format compatibility makes it easy to move existing documents into WPS, but it does not replace Acrobat's JavaScript form-authoring tools or guarantee that Acrobat scripts will run.

Open and work with PDF documents alongside other office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface to move from Microsoft Office to WPSAccess free, lightweight office tools in one suite
microsoft office alternative - wps office

Frequently Asked Questions

Where do I add JavaScript to a PDF button in Acrobat?

In Prepare a form, open the button's Properties > Actions. Select Mouse Up, choose Run a JavaScript, and click Add.

Why doesn't my form script find a field?

Check the field's name in its Properties dialog and make sure the name in `this.getField()` matches it exactly.

Can every PDF viewer run Acrobat JavaScript?

No. JavaScript support and permissions vary among PDF viewers. Test the form in the viewer your recipients will use, especially if scripts add or remove fields.

How do I stop a user from entering an out-of-range percentage?

Open the field's Properties > Validate and add a custom validation script. Use `app.alert()` to explain the limit and set `event.rc = false` to reject an invalid entry.