How to Use an Array of Field Names with Acrobat Combo Boxes
Question details
The user needs to correctly iterate through a JavaScript array of field names to update multiple Acrobat combo boxes without triggering a "not a function" error.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing a JavaScript loop to dynamically update items in multiple combo box fields within a PDF form.
- Observed behavior
- Calling setValue or setItems directly on the array elements throws a "not a function" error because the array contains string names instead of field objects. A misplaced semicolon also prematurely terminates the for loop.
Before modifying your form scripts, verify the exact names of your combo box fields in the PDF form properties and ensure your JavaScript console is open to catch syntax errors.
Use getField and Fix Loop Syntax
Convert string names to field objects using the getField method and ensure your for loop is syntactically correct.
When iterating through an array of field names in Acrobat JavaScript, the array holds string values. Acrobat requires actual field objects to execute methods like setItems or setValue. You must dynamically retrieve the object using the string name.
Additionally, placing a semicolon immediately after the for loop parameters causes the loop to terminate instantly, executing the subsequent code block only once.
Check your loop declaration. If you have "for (i = 0; i < myArray.length; i++);", delete the semicolon at the end so the loop correctly targets the block of code inside the curly braces.
Inside the loop, do not call methods directly on myArray[i]. Instead, pass the array element to the getField method by writing "this.getField(myArray[i])".
Chain your method to the retrieved object to populate the combo box. Your final code inside the loop should look like: "this.getField(myArray[i]).setItems([\"1\", \"2\"], [\"3\", \"4\"]);".
Create and Manage PDF Forms Easily with WPS Office
WPS Office provides an intuitive, comprehensive PDF editor that allows you to easily create interactive forms, add combo boxes, and manage field properties visually without writing complex JavaScript.
- 1. Open your PDF form: Launch WPS Office and open your existing PDF form or create a new blank document.
- 2. Navigate to the Form tab: Click on the 'Form' tab in the top ribbon to access all interactive form creation tools.
- 3. Add or Edit Combo Boxes: Select the 'Combo Box' tool and click anywhere on the page to insert a new dropdown field, or click an existing one to edit it.
- 4. Configure Properties Visually: Double-click the combo box to open its properties panel. Here, you can easily add, remove, and reorder list items without writing any JavaScript.

Frequently Asked Questions
Why do I get a "not a function" error when using setItems on my array?
This happens because your array contains the string names of the fields, not the field objects themselves. You must use this.getField(array[i]) to convert the string into a valid field object before calling setItems.
How do I populate a combo box using JavaScript in a PDF?
You can populate a combo box by using the setItems method on the field object. For example, this.getField("ComboBoxName").setItems(["Option 1", "Option 2"]); will replace the current dropdown list with those specific options.
What happens if I put a semicolon at the end of a for loop statement?
A semicolon immediately after the for loop condition acts as an empty statement, terminating the loop. The code block following it will execute exactly once, entirely independently of the loop's intended iteration.




