How to Add an OK or Cancel Warning Before Resetting a PDF Form
Question details
The user needs to display a confirmation dialog box (OK or Cancel) when a reset button is clicked in a PDF form to prevent unintentional deletion of form data.

- Product
- Adobe Acrobat / PDF
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form and configuring a reset button to clear user input safely.
- Observed behavior
- By default, a reset button instantly clears all form data. The goal is to intercept this action with a warning prompt that allows the user to confirm or cancel the reset.
Ensure you have a PDF editor with form editing and JavaScript capabilities installed, and that your PDF already contains a configured interactive button field.
Add a JavaScript Action to the Reset Button
Replace the default 'Reset a form' action with a custom JavaScript snippet that triggers a confirmation popup before executing the reset command.
Using a simple JavaScript code allows you to intercept the button click. The script uses the app.alert method to display a question. If the user selects 'OK', the form clears; if they select 'Cancel', nothing happens.
Open your PDF form in editing mode. Right-click the Reset button you created and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. If 'Reset a form' is listed in the Actions box, select it and click the 'Delete' button to remove the default behavior.
In the 'Select Action' dropdown, choose 'Run a JavaScript' and click the 'Add' button to open the JavaScript Editor.
Enter the following code: var nResponse = app.alert({cMsg: "Are you sure you want to clear all data?", nIcon: 2, nType: 2, cTitle: "Reset Form Warning"}); if (nResponse == 4) { this.resetForm(); } and click 'OK'.
Close the form editing mode and click your button. A dialog box should appear, allowing you to proceed with 'OK' or abort with 'Cancel'.

Manage and Fill PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to effortlessly manage, fill, and sign interactive PDF forms without needing complex configurations.
- 1. Open WPS Office: Launch WPS Office and click on the 'PDF' tab on the home screen.
- 2. Load Your PDF Form: Click 'Open' and select the interactive PDF form you want to fill or edit.
- 3. Fill or Edit the Form: Use the tools provided in the PDF viewer to input text, check boxes, or interact with buttons seamlessly.
- 4. Save and Share: Once completed, click 'Save' to preserve your form data, or use the share options to send the document directly.

Frequently Asked Questions
Can I customize the warning message in the JavaScript dialog?
Yes, you can modify the text inside the cMsg parameter of the app.alert function to display your own custom warning, such as 'Do you really want to delete your progress?'.
What happens if the user clicks Cancel or presses Escape?
The JavaScript condition checks the user's response. If Cancel or Escape is pressed, the script simply terminates without executing the this.resetForm() command, leaving all form data completely intact.
Does this JavaScript warning work in all PDF viewers?
While it works perfectly in full-featured PDF software like Adobe Acrobat and WPS Office, some basic built-in web browser PDF viewers might not fully support interactive JavaScript actions.




