Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Adding items to combobox using javascript

Avatar

Level 2

This question might seem silly, but for some reason the following code is not working for me

ddlNumbers.clearItems();
ddlNumbers.setItems([["California", "CA"],["Massachusetts", "MA"],["Arizona", "AZ"]]);

I execute this code in the click event handler of a button. For some reason the dropdown does not show these items, it only shows "Empty". What am I doing wrong?

When I do

     ddlNumbers.setItems("California");

     ddlNumbers.setItems("Massachusetts");

     ddlNumbers.setItems("Arizona");

Only last item (Arizona in this case) gets added to the combobox. I need to be able to set both text and value for the dropdown list.

Thanks
Shreedhar

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Shreedhar,

If you have a look at John Brinkman's blog: http://blogs.adobe.com/formfeed/2009/01/populating_list_boxes.html

You will see that the syntax for setItems() is different: coma separated list of display values and bound values, followed by the number of columns, currently "2".

Currency.setItems("US Dollar,USD,Canadian Dollar,CAD,Euro,EUR,United Kingdom Pounds,GBP", 2);

Hope that helps,

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi Shreedhar,

If you have a look at John Brinkman's blog: http://blogs.adobe.com/formfeed/2009/01/populating_list_boxes.html

You will see that the syntax for setItems() is different: coma separated list of display values and bound values, followed by the number of columns, currently "2".

Currency.setItems("US Dollar,USD,Canadian Dollar,CAD,Euro,EUR,United Kingdom Pounds,GBP", 2);

Hope that helps,

Niall

Avatar

Level 2

ahh, this works like a charm.I would never have figured this out by myself. The js_api_reference.pdf that is provided by Adobe has some incorrect information regarding setItems.

Thanks a lot. Much appreciated.

Shreeedhar