PDA

Click to See Complete Forum and Search --> : another js one - Array Q


alex_read
Jan 3rd, 2002, 10:41 AM
Function CreateInitialArray() {
var intCounter;
var strTemp;

for(intCounter=0; intCounter<theform.lstbox.options.length; intCounter++) {
strAry[intCounter] = theform.lstbox.options[intCounter].text;
strTemp = strTemp + strAry[intCounter] + "\n";
}
alert(strTemp);
}
Hi all. I'm using that one to loop through a <Select> listbox on a web page, and adding each line or entry from this listbox into an array. A string's then created of all the array elements before showing this in a messagebox.

I keep getting "undefined" before the first entry though - below is an example of how this comes out. Whats the reasoning behind this please ?!?!? :confused: :
UndefinedOne
Two
Three

CiberTHuG
Jan 3rd, 2002, 10:46 AM
*shrug*

Try setting strTemp to and empty string before the loop.

I don't guess JavaScript has a += operator.

alex_read
Jan 3rd, 2002, 10:48 AM
Yeah, that did it, thanks !