PDF Editing Issues

How to Reset a PDF Form and Return to Page One with JavaScript

Khadija KhanKhadija Khan Nov 3, 2026 869 views

Question details

The user wants to add a confirmation dialog to a PDF form's reset button and redirect the user back to the first page upon confirmation using JavaScript.

How to Reset an Acrobat Form and Return to Page One with JavaScript
Product
PDF
Device & OS
not provided
Scenario
Creating an interactive PDF form with a reset button that requires user confirmation to prevent accidental data loss, followed by returning to the start of the document.
Observed behavior
The user needs the exact JavaScript syntax to trigger a warning dialog, clear the form fields if accepted, and navigate to page one.
Before you start

Ensure you are using a PDF editor that fully supports JavaScript execution, such as Adobe Acrobat Pro, and remember to save a backup copy of your form before adding custom scripts.

Solution 1Recommended

Implement JavaScript on the Reset Button's MouseUp Event

Use a custom JavaScript code snippet on the button's action trigger to display an alert, reset the form, and navigate to the first page.

In Adobe Acrobat, you can assign custom JavaScript to interactive elements like buttons. By attaching a script to the 'Mouse Up' event of your reset button, you can invoke a confirmation dialog before any form data is cleared. Furthermore, Acrobat's JavaScript API uses a zero-based index for page numbers, meaning page 1 is represented by the number 0.

1
Enter form preparation mode

Open your PDF document in Adobe Acrobat and select 'Prepare Form' from the tools menu to make the form fields editable.

2
Access button properties

Right-click the reset button on your form, select 'Properties' from the context menu, and navigate to the 'Actions' tab.

3
Add a JavaScript action

In the 'Select Trigger' dropdown, choose 'Mouse Up'. In the 'Select Action' dropdown, choose 'Run a JavaScript', and then click the 'Add' button.

4
Input the script

In the JavaScript Editor window, paste the following code: if (app.alert({cMsg: "Do you want to restart?", cTitle: "Restart Warning", nIcon: 2, nType: 2}) == 4) { this.resetForm(); this.pageNum = 0; }

5
Save and test

Click 'OK' to save the script, close the properties window, exit the form editing mode, and test your new reset button.

Implement JavaScript on the Reset Button's MouseUp Event
Understanding the Script: In the app.alert function, 'nIcon: 2' displays a question mark icon, and 'nType: 2' creates 'Yes' and 'No' buttons. The value '4' corresponds to the user clicking 'Yes'. The 'this.pageNum = 0' command sends the user to the first page because page numbering in Acrobat JavaScript starts at zero.
WPS PDF Editor

Manage and Fill PDF Forms Easily with WPS Office

WPS Office offers a comprehensive, lightweight PDF editor that allows you to easily view, fill, and manage PDF forms. It serves as a powerful, user-friendly alternative to heavy PDF software for all your daily document needs.

  1. 1. Download and Install: Download WPS Office for free from the official website and install it on your device.
  2. 2. Open Your PDF: Launch WPS Office and open your interactive PDF form directly within the application.
  3. 3. Fill the Form: Click on the fillable fields to input your data easily. WPS Office automatically recognizes standard interactive form elements.
  4. 4. Save Your Document: Once filled out, use the 'Save' or 'Export to PDF' function to securely save your completed form locally or to WPS Cloud.
Seamlessly fill out and save interactive PDF forms without complex setups.Highly compatible with standard PDF formats and Adobe Acrobat files.Lightweight software that runs smoothly on Windows, Mac, Linux, iOS, and Android.Free basic PDF editing, viewing, and annotation capabilities built directly into the suite.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't my JavaScript code run in certain PDF viewers?

Not all PDF viewers support JavaScript execution. For interactive features like custom alerts and scripted form resets to work, the document must be opened in a compatible application like Adobe Acrobat. Many default web browser PDF viewers block or strip these scripts for security reasons.

Can I reset only specific fields instead of the whole PDF form?

Yes. You can pass an array of field names to the resetForm() function to clear only those specific fields. For example, using this.resetForm(["ClientName", "ClientEmail"]); will leave all other form fields intact.

Why is my PDF redirecting to the second page when I use this.pageNum = 1?

Acrobat's JavaScript API utilizes a zero-based index for its pages. Therefore, 0 represents page one, 1 represents page two, and so forth. You should always subtract one from your actual target page number when writing navigation scripts.

How do I change the title of the alert box in Acrobat JavaScript?

You can change the title of the alert box by modifying the 'cTitle' parameter within the app.alert function. For instance, cTitle: "Confirm Reset" will display 'Confirm Reset' in the dialog box's title bar.