Other PDF Issues

How to Populate an Acrobat PDF Combo Box with a Country List Using JavaScript

Aamir Naveed AkramAamir Naveed Akram Nov 10, 2026 869 views

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.

How to Populate an Acrobat Combo Box with a Country List Using JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Prepare your PDF form

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').

2
Open the JavaScript Console

Access the JavaScript Debugger or open a Document Action (like a temporary 'Mouse Up' event on a button) where you can execute a script.

3
Define the country array

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).

4
Apply the setItems() method

Call the method on your combo box field by adding the following line below your array: this.getField("MyList").setItems(aCountries);

5
Execute the script

Run the script. Exit form editing mode and click on your combo box to verify that it now displays the full list of countries.

Use the setItems() Method with a JavaScript Array
Best Practice: Adding a hyphen '-' or text like 'Select a Country' as the first item in your array ensures the dropdown does not default to the first alphabetical country before the user makes a choice.
Advanced PDF Editing

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. 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. 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to reveal various interactive field options.
  3. 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.
Easily insert and customize combo boxes, text fields, and checkboxes in PDF forms.Highly compatible with standard Microsoft Office formats, allowing seamless conversion between Word, Excel, PowerPoint, and PDF.Lightweight, fast, and features an intuitive interface for both beginners and advanced users.Completely free to download with powerful built-in PDF management tools.
microsoft office alternative - wps office

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.