PDF Editing Issues

How to Create a Yes/No Confirmation Alert to Reset PDF Form Fields

Algirdas JasaitisAlgirdas Jasaitis Nov 24, 2026 868 views

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.

How to Create a Yes/No Confirmation Alert When Resetting PDF Form Fields
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Button Properties

Open your PDF form in editing mode, right-click the Reset button, and select Properties.

2
Add a JavaScript Action

Navigate to the Actions tab. Choose 'Run a JavaScript' from the Select Action drop-down menu, and click Add.

3
Insert the Code

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(); }

4
Save and Test

Click OK to save the script, close the properties dialog, and test the button in viewing mode to ensure the prompt appears.

Use JavaScript to Prompt Before Resetting All Form Fields
Understanding the Alert Parameters: In app.alert(message, 2, 2), the first '2' indicates a warning icon, and the second '2' specifies a Yes/No button layout. The return value '4' corresponds to the user clicking 'Yes'.

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. 1. Open the Form Tab: Open your document in WPS Office and navigate to the 'Form' tab on the top ribbon.
  2. 2. Insert a Push Button: Select the Push Button tool and draw it onto your PDF document.
  3. 3. Access Action Properties: Right-click the new button, choose Properties, and click on the Actions tab.
  4. 4. Apply JavaScript: Set the action to 'Run a JavaScript', paste your confirmation code, and save the document.
Easily add, edit, and configure interactive PDF form fields.Seamless support for advanced PDF form JavaScript actions and triggers.High compatibility with Adobe Acrobat PDF document formats.Lightweight alternative for everyday PDF editing and creation tasks.
microsoft office alternative - wps office

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.