PDF Editing Issues

How to Run Acrobat JavaScript Only When User Selects Yes

Kushani NimanthikaKushani Nimanthika Nov 2, 2026 869 views

Question details

The user needs to configure a PDF form button to execute subsequent JavaScript commands only when the user clicks 'Yes' in a confirmation dialog box.

How to Run Acrobat JavaScript Only When a User Selects Yes
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Adding a Yes-or-No confirmation prompt to an interactive PDF button before proceeding with document actions like 'Save As'.
Observed behavior
If commands are placed in separate action sequences, they run regardless of the user's choice in the alert. The execution needs to halt completely if 'No' is selected or the dialog is closed.
Before you start

Ensure you have access to the Prepare Form toolset in your PDF editor and identify the specific interactive button where the confirmation dialog needs to be applied.

Solution 1Recommended

Combine All Actions into a Single Conditional Script

By placing the alert and all subsequent commands within a single JavaScript block, you can evaluate the user's response and prevent unwanted actions from executing.

A common mistake is assigning a JavaScript alert to a button and then adding a separate 'Execute Menu Item' action. The PDF software executes all listed actions sequentially, meaning the menu item will run even if the user clicks 'No'. To fix this, everything must be consolidated into one JavaScript action.

1
Open Button Properties

Enter Prepare Form mode in your PDF editor, right-click the target interactive button, and select Properties.

2
Remove Separate Actions

Navigate to the Actions tab and remove any existing non-JavaScript actions (such as 'Execute Menu Item') that are currently attached to the button.

3
Add a JavaScript Action

Select 'Run a JavaScript' from the 'Select Action' dropdown menu and click the Add button.

4
Insert the Conditional Code

In the JavaScript Editor, wrap your remaining actions inside an if statement that checks for a return value of 4. For example: if (app.alert({cMsg: 'Continue?', cTitle: 'Confirmation', nType: 2}) === 4) { app.execMenuItem('SaveAs'); }

5
Save and Test

Click OK to save the script, close the Properties dialog box, exit form editing mode, and click the button to test your conditional execution.

Combine All Actions into a Single Conditional Script
Alert Return Values: In Acrobat JavaScript, clicking 'Yes' returns the integer 4, while clicking 'No' returns 3. Evaluating strictly against 4 ensures the script only proceeds on a positive confirmation.
Free Microsoft Office alternative

Looking for a Lightweight PDF and Office Suite?

While advanced script debugging is specific to Adobe Acrobat, WPS Office provides a comprehensive, lightweight, and free alternative for managing all your document needs. From editing standard PDF forms to creating Word documents and Excel spreadsheets, WPS Office offers seamless format compatibility and a familiar interface.

  1. 1. Download and Install: Visit the official WPS Office website to download the free application for your operating system.
  2. 2. Open Your Documents: Launch WPS Office and easily open your existing PDF, DOCX, XLSX, and PPTX files without losing any formatting.
  3. 3. Edit and Manage PDFs: Use the dedicated PDF tab to fill out forms, add annotations, or convert PDFs to other editable formats.
Fully compatible with standard PDFs and Microsoft Office formats (Word, Excel, PowerPoint).Lightweight installation that won't slow down your computer's performance.Built-in PDF editor for viewing, annotating, and managing PDF pages seamlessly.Familiar tabbed interface allows you to handle multiple document types in one window.
microsoft office alternative - wps office

Frequently Asked Questions

Why do my other button actions run even if I click No in the alert?

The software executes all actions listed in the button's properties sequentially. A JavaScript alert cannot stop a separate, non-JavaScript action (like an Execute Menu Item command) from running. You must combine them into a single script.

What is the correct syntax to show a Yes/No dialog in PDF JavaScript?

You can create a Yes/No dialog using the app.alert method with the parameter nType: 2 (or 'YesNo'). For example: app.alert({cMsg: 'Message', nType: 2}).

How do I trigger a Save As dialog using Acrobat JavaScript?

You can trigger the Save As dialog within your script by executing app.execMenuItem('SaveAs');. Ensure this command is placed inside your conditional block so it only runs when the user confirms.