How to Populate PDF Drop-Down Lists from Name Fields Using JavaScript
Question details
The user needs to dynamically populate action-item assignment drop-down menus in a PDF form using the data entered into attendee name fields.

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive meeting-notes PDF form where action items must be assigned to attendees whose names are entered dynamically into text fields.
- Observed behavior
- The user successfully used JavaScript to populate the drop-down lists but noticed that updating the list removes existing selections, and clicking a 'Clear Form' button causes the refresh script to stop working.
Ensure you have access to a PDF editor with advanced form creation and JavaScript execution capabilities. Identify the exact field names for both your name text fields and your target drop-down lists before writing the script.
Use JavaScript setItems to Populate the Drop-Down List
Create a custom JavaScript action triggered by a button to read the text fields, build an array of non-empty names, and populate the drop-down list.
You can trigger the JavaScript either through a dedicated 'Refresh List' button or an 'On Blur' event when the name fields lose focus. Building an array of non-empty values ensures clean drop-down options.
Be aware that whenever the drop-down list is refreshed, any existing selections made by the user will be reset. Additional logic is required if you want to retain the selected assignee while updating the rest of the list.
Open your PDF form editor, insert a Button form control onto the page, and label it 'Refresh Assignees'.
Right-click the button, open its Properties, navigate to the Actions tab. Select 'Run a JavaScript' from the 'Select Action' menu and click 'Add'.
In the JavaScript editor, define an empty array. Write a script to retrieve the values of the attendee fields (e.g., this.getField('Attendee1').value). If the value is not empty, push it to your array.
Use the setItems method on your target drop-down field to apply the array: this.getField('AssigneeDropdown').setItems(yourArrayName).
To prevent errors after a 'Clear Form' action, add an if-statement to ensure the setItems method is only called, or handles a default value (like ' '), when the array is empty.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides robust and intuitive PDF form editing tools, allowing you to seamlessly insert text fields, buttons, and drop-down menus without needing complex programming for standard tasks.
- 1. Open the PDF: Launch WPS Office and open your PDF document.
- 2. Access Form Tools: Navigate to the 'Form' tab in the top ribbon menu to access the interactive form controls.
- 3. Insert a Drop-Down List: Click the 'Combo Box' or 'Drop-Down List' icon, then click on the page area where you want to place the menu.
- 4. Configure Properties: Double-click the newly created field to open its Properties window, where you can manually add list items, format text, and assign actions.

Frequently Asked Questions
Why do my drop-down selections disappear when the list updates?
Using the setItems JavaScript method completely rebuilds the options within the drop-down list. Because the underlying list structure is replaced, any previously selected value is cleared by default.
How do I prevent the 'Clear Form' button from breaking my JavaScript?
When 'Clear Form' empties the name fields, your script might attempt to populate the drop-down with null or invalid data. To fix this, update your script to check if the generated array has a length greater than zero before executing the setItems command.
Can I update the drop-down automatically without using a refresh button?
Yes. Instead of a button, you can add your JavaScript to the 'On Blur' (lose focus) action of each attendee name field, or use a document-level calculation script. However, this means the drop-down will reset every time a user types in those fields, which can be frustrating if they have already made assignments.




