How to Create a Yes/No Confirmation Alert to Reset PDF Form Fields
Question details
The user wants to add a confirmation prompt (Yes/No dialog) before users can clear or reset PDF form data, preventing unintended data deletion.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form with a reset button.
- Observed behavior
- Currently, the reset button clears the form immediately without warning, risking accidental loss of filled data. The goal is to show a Yes/No prompt first.
Ensure your PDF editor supports JavaScript actions for form fields and have the exact names of any specific fields you want to include or exclude from the reset process ready.
Use JavaScript to Prompt Before Resetting All Form Fields
Attach a custom JavaScript action to your reset button that triggers an alert box, executing the reset only if the user clicks "Yes".
This method leverages the app.alert function built into PDF JavaScript to create a standard Yes/No popup dialog.
When the user clicks 'Yes', the script receives a specific return value and then executes the command to clear the form data.
Open your PDF form in editing mode, right-click the Reset button, and select Properties.
Navigate to the Actions tab. Choose 'Run a JavaScript' from the Select Action drop-down menu, and click Add.
Paste the following code into the JavaScript editor: if (app.alert("Are you sure you want to reset the form?", 2, 2) == 4) { this.resetForm(); }
Click OK to save the script, close the properties dialog, and test the button in viewing mode to ensure the prompt appears.

Reset Specific Fields While Preserving Read-Only Formulas
Modify the script to target only specific input fields, ensuring read-only boxes containing formulas are not accidentally erased.
Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides comprehensive PDF editing tools, allowing you to easily design interactive forms, manage field properties, and integrate essential JavaScript actions like reset confirmations.
- 1. Open the Form Tab: Open your document in WPS Office and navigate to the 'Form' tab on the top ribbon.
- 2. Insert a Push Button: Select the Push Button tool and draw it onto your PDF document.
- 3. Access Action Properties: Right-click the new button, choose Properties, and click on the Actions tab.
- 4. Apply JavaScript: Set the action to 'Run a JavaScript', paste your confirmation code, and save the document.

Frequently Asked Questions
Can I change the warning message in the popup dialog?
Yes, you can customize the text inside the quotation marks in the app.alert function. For example, app.alert("Clear all data?", 2, 2) will display "Clear all data?" instead of the default message.
What happens if the user clicks 'No' on the alert?
If the user clicks 'No', the app.alert function returns a value of 3 instead of 4. Since the 'if' condition specifically checks for a value of 4, the this.resetForm() command is bypassed, and the form data remains intact.
Why does my reset script erase my read-only formula fields?
By default, this.resetForm() clears all fields in the document. To prevent read-only formula fields from being erased, you must pass an array of specific field names to the reset function, such as this.resetForm(["Field1", "Field2"]);.
Do I need programming experience to add this alert?
No advanced programming experience is required. You simply need to copy and paste the provided one-line JavaScript snippet into the button's action properties within your PDF editor.




