PDF Editing Issues

How to Run Custom JavaScript from an Acrobat PDF Button

Olivia MillerOlivia Miller Oct 28, 2026 869 views

Question details

The user wants to know how to trigger and execute custom JavaScript code using a button within a PDF form.

How to Run Custom JavaScript from an Acrobat PDF Button
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Adding interactive scripts to a PDF form to manipulate field values when a user clicks a button.
Observed behavior
The user needs to correctly reference field objects within the Actions tab of a button's properties to read or write data.
Before you start

Ensure you have Adobe Acrobat Pro or a compatible PDF editor with advanced form editing capabilities, and a basic understanding of Acrobat JavaScript API syntax.

Solution 1Recommended

Configure Custom JavaScript in Button Properties

Use the Actions tab in the PDF button's properties to add and execute custom JavaScript code using the Acrobat API.

In Adobe Acrobat, buttons can be configured to perform a variety of actions, including running complex JavaScript sequences. To modify or read form fields accurately, you must utilize the specific Acrobat JavaScript API, referencing field objects with the getField method rather than standard web JavaScript functions.

1
Access Button Properties

Open your PDF form in Adobe Acrobat. Enter 'Prepare Form' mode from the right-hand tool pane, right-click the target button, and select 'Properties'.

2
Navigate to the Actions Tab

In the Button Properties dialog box, click on the 'Actions' tab to configure the interactive behavior of your button.

3
Select the JavaScript Action

In the 'Select Action' dropdown menu, choose 'Run a JavaScript', and then click the 'Add...' button to open the JavaScript Editor.

4
Enter the JavaScript Code

In the JavaScript Editor window, input your custom code. To read a field value and assign it to another, use code like: var target = this.getField('Text1'); target.value = this.getField('Mark1').valueAsString;.

5
Save and Test

Click 'OK' to save your script and close the editor. Close the Button Properties window, exit Form Editing mode, and click the button to test your JavaScript.

Configure Custom JavaScript in Button Properties
Proper Field Referencing: Always use the this.getField() method to reference PDF form fields. Assigning string variables directly will not update the actual form fields in the PDF document.
Edit PDFs Efficiently

Manage and Fill PDF Forms Easily with WPS Office

WPS Office features a powerful PDF editor that allows you to effortlessly read, fill, and modify interactive PDF forms. Try it as a lightweight, fast, and highly compatible solution for your daily document management.

  1. 1. Open Your Interactive PDF: Launch WPS Office and open your PDF document containing the interactive forms and buttons.
  2. 2. Access Form Controls: Navigate to the PDF editor interface where you can view and interact with text fields, checkboxes, and buttons natively.
  3. 3. Fill and Save: Click the form buttons to execute their embedded actions or enter your data, then click 'Save' to preserve your inputs securely.
Read and fill interactive PDF forms seamlessly with a user-friendly interfaceFully compatible with standard Adobe PDF formats and Microsoft Word, Excel, and PowerPoint filesLightweight architecture ensures smooth performance on Windows, Mac, and mobile platforms
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my PDF button JavaScript executing?

Ensure that JavaScript execution is enabled in your PDF reader's security preferences. In Adobe Acrobat, go to Edit > Preferences > JavaScript and verify that 'Enable Acrobat JavaScript' is checked.

Can I use standard web JavaScript in a PDF form?

No, PDF JavaScript uses a specialized API developed specifically for PDFs (Acrobat JavaScript API). Standard web browser objects like document.getElementById or window are not supported; you must use native objects like this.getField().

How do I read the value of a text field using JavaScript in a PDF?

You can read a text field's value by assigning it to a variable using the syntax: var myValue = this.getField('FieldName').value;. Ensure the field name in the script matches the exact name of the form field.

Are JavaScript calculations automatic in PDF forms?

Scripts added through the Calculation tab run automatically whenever associated field values change. However, scripts added to a button's Actions tab require a specific trigger event, such as a user clicking the button (Mouse Up).