How to Populate Acrobat Dropdown Lists from Text Fields Using JavaScript
Question details
The user wants to dynamically populate repeated PDF dropdown fields with names entered in two separate text fields, ensuring the dropdown updates whenever the text field values change.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where dropdown list items depend on user input from other text fields.
- Observed behavior
- The dropdown options need to automatically update with the exact values entered into the designated text fields.
Ensure you have access to the 'Prepare Form' tools in Adobe Acrobat and basic familiarity with adding custom JavaScript to form fields.
Apply Custom Validation Scripts to Text Fields
Use JavaScript to trigger an update to the dropdown menu whenever the user inputs a value into the text fields.
This method leverages custom validation scripts applied directly to the text fields. When a text field's value changes, the script updates the items available in the target dropdown field.
Open your PDF in Adobe Acrobat and enter the 'Prepare Form' mode to view all your interactive form fields.
Right-click the first text field (e.g., 'name1') and select 'Properties'. Go to the 'Validate' tab and select 'Run custom validation script'. Enter the following JavaScript: this.getField('NameSelection').setItems(['', event.value, this.getField('name2').valueAsString]);
Right-click the second text field (e.g., 'name2') and select 'Properties'. Under the 'Validate' tab, enter the following custom validation script: this.getField('NameSelection').setItems(['', this.getField('name1').valueAsString, event.value]);
Replace 'NameSelection' in the code with the actual field name of your dropdown list. Ensure the text field names ('name1' and 'name2') exactly match the field names in your document.

Edit and Manage PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to create, edit, and fill interactive PDF forms efficiently without needing expensive software.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in PDF Editor.
- 2. Access form tools: Navigate to the 'Form' tab to view all interactive form controls like Text Fields, Checkboxes, and Dropdown Menus.
- 3. Edit field properties: Double-click any form field to open its Properties panel, where you can configure options, formatting, and interactive behaviors.

Frequently Asked Questions
Why does my dropdown selection reset when I type in the text field?
Because the JavaScript validation script uses the setItems method to completely rebuild the dropdown's list of options. When this happens, any previously selected value in the dropdown is cleared.
Can I populate multiple dropdown fields at the same time?
Yes. If your dropdown fields have different names, you can update each one separately within the same script by adding a setItems line for each target field, or use a document-level script to loop through them.
What if I want more than two text fields to feed into the dropdown?
You can expand the array inside the setItems function. Just add additional this.getField('nameX').valueAsString elements into the array for every new text field you want to include in the dropdown options.




