How to Automatically Clear Related PDF Form Fields using JavaScript
Question details
The user wants to use JavaScript to automatically clear subsequent PDF form fields in a row when the first field is left blank.

- Product
- PDF Form Editors
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where fields are interdependent, specifically clearing an entire row of data if the primary field is emptied.
- Observed behavior
- Needs a custom calculation script to automatically make related fields blank based on the string value of the first field in a row.
Ensure your PDF editing software supports JavaScript for interactive forms and identify the exact field names you intend to link together.
Use a Custom Calculation Script to Clear Dependent Fields
Add a JavaScript calculation script to the dependent fields that checks the primary field's value and clears itself if the primary field is blank.
This method uses the 'valueAsString' property to evaluate the first field in the row. If the primary field is empty, the script automatically applies an empty value to the current field during the calculation event.
Right-click the dependent PDF form field you want to clear automatically and select 'Properties' from the context menu.
In the Properties dialog box, go to the 'Calculate' tab and choose the 'Custom calculation script' option.
Click 'Edit' and enter this code: if (this.getField('Name of first field in row').valueAsString == '') event.value = ''; (Replace 'Name of first field in row' with the actual exact name of your primary field).
Click 'OK' to save the script, close the properties window, and test your form by clearing the primary field to ensure the dependent field also goes blank.

Manage and Edit PDF Forms Easily with WPS Office
WPS Office features a powerful PDF editor that allows you to easily edit text, fill out interactive forms, and manage your PDF documents seamlessly. It's fully compatible with standard PDF features, ensuring your documents look perfect every time.
- 1. Open your PDF Document: Launch WPS Office and open your interactive PDF form document.
- 2. Navigate to the Form Tools: Click on the 'Form' or 'Edit' tab on the top ribbon to view and interact with the available fields.
- 3. Fill or Edit Fields: Click directly on the form fields to enter your data or modify the layout using the comprehensive editing tools.
- 4. Save your Changes: Click the 'Save' icon or press Ctrl+S to preserve your filled or modified PDF form securely.

Frequently Asked Questions
Why isn't my PDF JavaScript calculating automatically?
Ensure that 'Automatically calculate field values' is enabled in your PDF editor's preferences. If this setting is disabled, calculation scripts will not run automatically when other fields are updated.
Can I use this script to clear an entire row of PDF fields at once?
You will need to apply this calculation script to each dependent field in the row individually. Alternatively, you can write a more complex document-level script or action attached to the primary field that explicitly resets multiple fields by name.
Does WPS Office support editing interactive PDF forms?
Yes, WPS Office PDF supports filling out interactive PDF forms, adding signatures, and managing standard form fields. However, for authoring complex custom JavaScript calculations, you may require a specialized form authoring environment.




