How to Reset PDF Form Fields on Drop-Down Selection Change
Question details
The user needs to dynamically clear hidden text fields and update calculated fields based on the option a user selects from a drop-down menu in a PDF form.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where specific text fields must appear or disappear depending on a drop-down choice, and the data in the hidden fields must be cleared to prevent incorrect submissions.
- Observed behavior
- The form utilizes JavaScript to dynamically update field visibility, resetting the values of hidden fields and copying relevant values to calculated fields upon selection change.
Ensure you have access to a professional PDF editor with form creation and JavaScript capabilities, such as Adobe Acrobat Pro or WPS Office, and verify the exact field names you wish to manipulate.
Use a Custom Calculation Script to Hide and Reset Fields
Add a custom calculation script to the drop-down field to automatically toggle the visibility of associated text fields and clear their contents when hidden.
By utilizing Acrobat JavaScript's display and resetForm methods, you can ensure that fields irrelevant to the current drop-down selection are not only hidden from the user but also wiped of any previously entered data.
Open your PDF form editor, right-click the drop-down field you want to trigger the action, and select 'Properties'.
Go to the 'Calculate' tab and select 'Custom calculation script', then click the 'Edit' button to open the JavaScript editor.
Write an if-else statement using event.valueAsString. For example, if option 'dd1' is selected, set this.getField('Text1').display = display.visible; and set the unwanted fields to display.hidden.
Immediately after hiding the unwanted fields in your script, add the command this.resetForm(['Text3', 'Text4']); to clear the data from those specific hidden fields.

Update Calculated Fields Using a Validation Script
Apply a custom validation script to the drop-down menu to automatically populate specific target fields with data from other text fields based on the user's choice.
Create and Edit Dynamic PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools that allow you to quickly design interactive forms, insert drop-down menus, manage text fields, and configure properties to streamline your document workflows.
- 1. Open Your PDF: Launch WPS Office and open the PDF document you want to turn into an interactive form.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form controls.
- 3. Insert Form Elements: Click on 'Drop-Down List' or 'Text Field' and drag the cursor on your page to place the interactive elements.
- 4. Configure Properties: Double-click the newly created form control to open its Properties panel, where you can define field names, appearance, and underlying values.

Frequently Asked Questions
Why aren't my hidden PDF fields clearing when I change the drop-down selection?
Hidden fields retain their data unless explicitly cleared. Merely setting the field to 'display.hidden' only removes it from view. You must include the 'this.resetForm(["FieldName"]);' JavaScript command to successfully delete the background data.
Where do I add the JavaScript in a PDF drop-down field?
Right-click the drop-down field and select 'Properties'. Depending on when you want the script to run, navigate to the 'Format', 'Validate', or 'Calculate' tab, select the option to run a custom script, and paste your JavaScript code there.
Are JavaScript PDF forms compatible with all PDF viewers?
Advanced JavaScript functions, like conditionally resetting form fields, require standard-compliant PDF readers such as Adobe Acrobat, WPS PDF, or Foxit. Basic browser-based PDF viewers often lack full JavaScript engine support and may not execute the scripts correctly.




