Skip to main content
Inspiring
February 25, 2021
Answered

Use Array of names to set Items in combobox

  • February 25, 2021
  • 3 replies
  • 1931 views

I am trying to loop an array to set Items in a long list of comboboxes. I keep getting not a function as a return.

 

var myArray=new Array ("combobox1","combobox2",etc);
for (i=0; i < myArray.length; i++);
{myArray[i].setvalue(["1","2"],["3","4"]);}

I keep getting myArray[i].setvalue is not a function. What am I doing wrong?  I am new to this so anyadvice is beneficial. Thanks for reading!

This topic has been closed for replies.
Correct answer Bernd Alheit

Use:

this.getField(myArray[i]).setItems( ... )

3 replies

Legend
February 27, 2021

By the way this line

for (i=0; i < myArray.length; i++);

does nothing at all. The following line

{myArray[i].setvalue(["1","2"],["3","4"]);}

will be run exactly once. This is because of the semi-colon on the for line, which runs everything BEFORE the semi-colon in a loop (so in this case runs nothing).

Inspiring
February 27, 2021

That is very good to know! Thank you for the claridication. 

try67
Community Expert
Community Expert
February 25, 2021

Also, myArray[i] returns a string, not a field. You need to use the getField method to access a field object.

Inspiring
February 27, 2021

Ah I see. Would there be any way to use getField on multiple fields? like getField ("1","2","3") etc? Or would I have to input each getField individually? 

Legend
February 27, 2021

You have to CALL getField for each field. You don't have to type it, you loop over your array and call it for each. But in general you can't take something made for one item and make it take a list, that's what loops are for.

Bernd Alheit
Community Expert
Community Expert
February 25, 2021

You must use setItems on the field objects. 

Inspiring
February 27, 2021

That was definitely my issue. would calling  getField("myArray[i]").setItems() not work then? 

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
February 27, 2021

Use:

this.getField(myArray[i]).setItems( ... )