How to Add a Yes/No Confirmation Before Clearing a PDF Form
Question details
The user needs to display a confirmation dialog before clearing form fields, ensuring the form only resets if 'Yes' is selected.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Setting up a 'Clear Form' button in a PDF document and wanting to prevent users from accidentally erasing all their inputted data.
- Observed behavior
- By default, the form clears immediately upon clicking the button. The goal is to intercept this action with a JavaScript alert dialog.
Ensure you have form editing permissions for the PDF document and access to the button's properties to add custom JavaScript actions.
Add Custom JavaScript to the Button's Mouse Up Event
Use a JavaScript alert condition on the button's Mouse Up action to require user confirmation before executing the form reset command.
By replacing the standard 'Reset a Form' action with a custom JavaScript snippet, you gain full control over when the form resets.
The app.alert method is used to display the dialog. The parameter '2' sets a warning icon, and the second '2' specifies that the dialog should display Yes/No buttons. A return value of 4 means the user clicked 'Yes'.
Enter the form editing mode in your PDF editor, right-click your 'Clear Form' button, and select Properties.
Navigate to the Actions tab. Select 'Mouse Up' as the trigger and choose 'Run a JavaScript' as the action, then click the Add button.
Paste the following script into the editor: if (app.alert('STOP! Do you want to clear this form?', 2, 2) == 4) { this.resetForm(); } Check that your quotation marks are standard straight quotes to prevent syntax errors.

Create and Manage PDF Forms Seamlessly with WPS Office
WPS Office provides a comprehensive PDF editor that makes it easy to fill, edit, and manage interactive PDF forms while offering robust alternatives to expensive software.
- 1. Open your PDF in WPS Office: Launch WPS Office and open the PDF document containing your interactive form.
- 2. Access the Form Tools: Navigate to the 'Form' or 'Edit PDF' tab on the top ribbon to view interactive form controls.
- 3. Fill or Edit Securely: Use the provided tools to fill out the form securely, manage form data, or edit document elements without needing complex scripts.

Frequently Asked Questions
Why does a JavaScript syntax error occur when I paste the script?
Syntax errors often happen if the script contains smart (curly) quotes instead of standard straight quotes. Re-type the quotation marks manually in the JavaScript editor to fix this issue.
What does the number 4 mean in the app.alert script?
In PDF JavaScript, when using the app.alert method with a Yes/No button configuration, the return value for the 'Yes' button is exactly 4. The script checks this value to ensure the user explicitly confirmed.
Can I use the standard Reset Form action alongside this JavaScript?
It is not recommended. If you keep the standard Reset Form action alongside the script, the form might reset before the JavaScript confirmation is even processed. Always remove the default reset action when using a script.




