Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Dropdownlists

Avatar

Level 1

Hi all

I have 2 dropdownlists;

- dropdownlist1

- dropdownlist2

I would like to set the items of dropdownlist 1 into dropdownlist2.

The following code does not work.

Have anybody the solution?


for(var i = 0;i< dropdownlist1.length;i++)
{

     dropdownlist2.addItem(  dropdownlist2.item(i) );
}

1 Reply

Avatar

Level 10

Hi,

Try this code,

var itemList = [];

for (var i = 0; i < dropdownlist1.length; i++)

{

    itemList.push(dropdownlist1.getDisplayItem(i));

}

dropdownlist2.setItems(itemList.join(","));

If you have "Specify Item Values" set on the binding tab of the drop down list object palette then you will need to copy the item value across as well, so

var itemList = [];

for (var i = 0; i < DropDownList1.length; i++)

{

    itemList.push(DropDownList1.getDisplayItem(i));

    itemList.push(DropDownList1.getSaveItem(i));

}

DropDownList2.setItems(itemList.join(","),2);

That is add the getSaveItem line (the fourth one) and a ",2" to the setItems call on the last line.

Regards

Bruce