How to Clear and Reset PDF Date Fields Using JavaScript
Question details
The user needs to use JavaScript to automatically clear PDF date fields and toggle their required status based on whether a checkbox is selected or cleared.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where a checkbox controls the validation and content of associated date fields.
- Observed behavior
- Directly assigning a value to the field using simple property assignment (e.g., field01.value = '') fails to clear the date fields as expected.
Ensure you have access to the JavaScript console in your PDF editor to identify the exact field names, as formatted date fields often have hidden system suffixes.
Use getField() with the Exact Acrobat Field Name
The most reliable method to target, clear, and change the required status of PDF form fields using their true internal names.
Directly assigning values to a field by its assumed name often fails because PDF editors append formatting suffixes to date fields. Utilizing the getField() method ensures you are referencing the correct object in the document structure.
Open your PDF editor's JavaScript console and use console.println to list or identify the true field names. Date fields created with formatting might receive names like 'DateRangeFrom_af_date'.
Assign the fields to variables using the this.getField() method. For example: var from = this.getField('DateRangeFrom_af_date'); var to = this.getField('DateRangeTo_af_date');.
Set the value property to an empty string to clear the dates when the checkbox is unchecked: from.value = ''; to.value = '';.
When the checkbox is selected, enforce validation by setting the required attribute: from.required = true; to.required = true;.

Use the resetForm() Method
An alternative approach to quickly clear fields by reverting them directly to their default, unpopulated state.
Manage PDF Forms Easily with WPS Office
WPS Office provides a user-friendly PDF editor to view, fill, and manage interactive PDF forms seamlessly. Easily handle data entry without needing complex JavaScript troubleshooting.
- 1. Download and install: Get WPS Office from the official website and launch the application.
- 2. Open your PDF form: Import your interactive PDF document into the WPS PDF Editor.
- 3. Fill or clear fields: Click on the date fields or checkboxes to fill out or clear the form data directly through the user interface.
- 4. Save your document: Click File and choose Save to preserve your updated form entries.

Frequently Asked Questions
Why does my JavaScript not recognize the PDF field name?
Formatted date fields in Adobe Acrobat often get automatic suffixes appended to their names, such as '_af_date'. You must use the JavaScript console to identify the actual system name rather than the display name.
How do I make a PDF field required using JavaScript?
You can use the required property on the field object. Target the field using this.getField('fieldName') and set its required property to true: this.getField('fieldName').required = true;.
Does resetForm() clear the entire PDF document?
Not necessarily. If you use resetForm() without parameters, it clears the whole form. However, if you pass an array of specific field names like this.resetForm(['field01']);, it will only reset those designated fields.
Why use defaultValue instead of an empty string?
Setting a field's value to its defaultValue is safer when dealing with calculated fields or dropdowns, as it restores the form to its original author-intended state rather than forcing a blank string that might break logic.




