PDF Editing Issues

How to Create a Confirmation Dialog in Acrobat JavaScript

Jason MillerJason Miller Nov 2, 2026 869 views

Question details

The user needs to implement a Yes/No confirmation dialog in Acrobat JavaScript to control the execution flow of a PDF script.

How to Create a Confirmation Dialog in Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Writing a script for a button action, document, or batch process in a PDF that prompts the user to confirm their intent before proceeding.
Observed behavior
Standard browser confirm() methods do not work in Acrobat JavaScript, causing the script to fail or behave unexpectedly.
Before you start

Determine exactly where your script will be executed (e.g., a button action, document script, or batch process), as Acrobat JavaScript requires specific PDF-native API methods rather than standard browser pop-ups.

Solution 1Recommended

Use the app.alert Method to Create a Yes/No Dialog

Replace standard browser confirm() methods with Acrobat's app.alert method configured to display custom Yes and No buttons.

Acrobat JavaScript does not support the standard web browser 'confirm()' function. Because PDFs run in a separate sandbox environment, you must use 'app.alert()' with specific parameters to create a prompt that returns a numerical value based on the user's choice.

1
Open the JavaScript Editor

Open your PDF editor, navigate to the form field or button you want to configure, right-click to open Properties, and access the Actions tab to add a Run a JavaScript action.

2
Define the app.alert parameters

Use the app.alert syntax to create a Yes/No question dialog. Write: var response = app.alert({cMsg: 'Do you want to continue?', nIcon: 2, nType: 2});

3
Evaluate the user's response

Set up a conditional statement to check the returned value. A return value of 4 means the user clicked 'Yes', while a value of 3 means the user clicked 'No'.

4
Insert your execution code

Wrap the rest of your intended script inside the condition to control the flow. For example: if (response == 4) { // Add code to continue here } else { // Add code to stop or exit here }

Use the app.alert Method to Create a Yes/No Dialog
Understanding app.alert properties: In the app.alert method, the 'nIcon' property sets the icon type (0=Error, 1=Warning, 2=Question, 3=Status) and 'nType' sets the button layout (0=OK, 1=OK/Cancel, 2=Yes/No, 3=Yes/No/Cancel).

Edit PDFs and Manage Forms Seamlessly with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to easily create interactive forms, add buttons, and edit PDF documents without writing complex JavaScript code from scratch. It is a lightweight, full-featured suite for all your document needs.

  1. 1. Install the software: Download and install the free version of WPS Office from the official website.
  2. 2. Open your PDF document: Launch WPS PDF and open the document you wish to edit or add forms to.
  3. 3. Navigate to form tools: Click on the 'Form' tab in the top ribbon to insert interactive fields, buttons, and configure actions visually.
  4. 4. Save and distribute: Save your fully interactive PDF document, which can now be seamlessly shared and used across different PDF readers.
Fully compatible with standard PDF formats and Adobe Acrobat interactive forms.Intuitive user interface for editing PDF text, images, and form fields effortlessly.Lightweight software that loads large, complex PDF files instantly.Cost-effective alternative packed with advanced PDF viewing and editing tools.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't the confirm() function work in my PDF script?

The standard confirm() function is part of browser-based JavaScript. PDF software environments use their own specific JavaScript API, meaning you must use application-specific methods like app.alert() to generate dialog boxes safely.

How do I stop a script from executing if the user clicks No in a PDF dialog?

Using the app.alert() method with nType set to 2 (Yes/No), capture the return value in a variable. If the user clicks No, the method returns 3. Wrap the rest of your script in an if-statement that only executes if the return value is 4 (Yes).

Can I use Acrobat JavaScript dialogs in batch processes?

While Acrobat JavaScript can be executed within batch processes (such as the Action Wizard), you should avoid scripts that require manual user interaction (like confirmation dialog boxes) if you want the batch process to run fully automatically.

Where do I add JavaScript to a PDF button?

Right-click the button field in Form Editing mode, select Properties, and go to the Actions tab. Choose 'Run a JavaScript' from the Select Action dropdown list, click Add, and paste your code into the resulting JavaScript Editor window.