How to Populate an Acrobat PDF Combo Box with a Country List Using JavaScript
Question details
The user wants to automatically populate a combo box (dropdown list) in a PDF form with a comprehensive list of countries using a script, rather than entering each country manually.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires users to select their country from a long dropdown list.
- Observed behavior
- Adding dozens of countries manually to a combo box's properties is tedious and time-consuming. A programmatic solution is needed to populate the options efficiently.
Ensure you have a professional PDF editor with form creation and document-level JavaScript execution capabilities, such as Adobe Acrobat Pro or WPS Office PDF.
Use the setItems() Method with a JavaScript Array
Execute a small JavaScript snippet that uses the setItems() method to quickly inject an array of country names directly into your combo box.
Instead of manually typing dozens of countries into the combo box properties, you can use the built-in PDF JavaScript API. The setItems() function accepts an array of strings and dynamically replaces the existing list of options in your target field.
Open your PDF in Form Editing mode and ensure your target combo box field is created. Note the exact name of the field (e.g., 'MyList').
Access the JavaScript Debugger or open a Document Action (like a temporary 'Mouse Up' event on a button) where you can execute a script.
Write an array containing your countries. For example: var aCountries = ["-", "United States", "Canada", "United Kingdom", "Australia", "Germany", "Japan"]; (expand this list to include all required countries).
Call the method on your combo box field by adding the following line below your array: this.getField("MyList").setItems(aCountries);
Run the script. Exit form editing mode and click on your combo box to verify that it now displays the full list of countries.

Create and Edit Interactive PDF Forms with WPS Office
WPS Office features a robust PDF editor that allows you to easily create interactive forms, add combo boxes, and manage form properties. It simplifies complex document tasks and boosts your productivity.
- 1. Open your PDF in WPS Office: Launch WPS Office, go to the PDF tab, and open the document you wish to convert into an interactive form.
- 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to reveal various interactive field options.
- 3. Insert a Combo Box: Click on 'Combo Box' and draw the field on your page. Double-click it to open its properties and manage its dropdown list easily.

Frequently Asked Questions
Can I set a default selected value in the combo box using JavaScript?
Yes. After populating the combo box with setItems(), you can set the default visible value by assigning a value directly to the field, for example: this.getField("MyList").value = "United States";
Can I use the setItems() script to clear the combo box?
Absolutely. If you want to empty the dropdown list, simply pass an empty array to the method: this.getField("MyList").setItems([]);
Does the setItems() method work on standard text fields?
No, the setItems() method is exclusively designed for choice-based form fields, such as combo boxes (dropdown lists) and list boxes. Attempting to use it on a standard text field will generate an error.
Where is the best place to run this one-time population script?
Since you only need to populate the list once, it is best to run it directly from the JavaScript Debugger/Console. Alternatively, you can temporarily attach the script to a new button's 'Mouse Up' action, click the button to populate the list, and then delete the button.




