Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You must use setItems on the field objects.
Copy link to clipboard
Copied
That was definitely my issue. would calling getField("myArray[i]").setItems() not work then?
Copy link to clipboard
Copied
Use:
this.getField(myArray[i]).setItems( ... )
Copy link to clipboard
Copied
Yes, the quotes would look for a field with that name not the array itself. Thank you very much for the help!
Copy link to clipboard
Copied
Hi. How would you set combobox items one at a time as if reading from records from a table?
Copy link to clipboard
Copied
Put the entries in a array and use the method setItems.
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
Bernd is correct, that is how you can add one item at a time by calling (myArray[x]) x being the number of the array entry you want to add and then using setItems.
this.getField("combobox").setItems(myArray[x]);
I am a little new but I think this will work. It sounds though like you want to automate the process?
Copy link to clipboard
Copied
Also, myArray[i] returns a string, not a field. You need to use the getField method to access a field object.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
That is very good to know! Thank you for the claridication.

