How to Create a Confirmation Dialog in Acrobat JavaScript
Question details
The user needs to implement a Yes/No confirmation dialog in Acrobat JavaScript to control the execution flow of a PDF script.

- 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.
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.
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.
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.
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});
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'.
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 }

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. Install the software: Download and install the free version of WPS Office from the official website.
- 2. Open your PDF document: Launch WPS PDF and open the document you wish to edit or add forms to.
- 3. Navigate to form tools: Click on the 'Form' tab in the top ribbon to insert interactive fields, buttons, and configure actions visually.
- 4. Save and distribute: Save your fully interactive PDF document, which can now be seamlessly shared and used across different PDF readers.

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.




