SYP}{ER
02-09-2003, 05:04 PM
function in_array (string,arrToSearch) {
retValue = 0;
for (i=0;i < arrToSearch.length;i++) {
if (arrToSearch[i] == string){
retValue = 1;
break;
}
}
return retValue;
}
That checks to see if an element exists in an array. Returns 0 on false, 1 on true.
Now, I use it when making my options like this:
l = obj.options.length;
for (i=0;i<cats[what].length;i++){
obj.options[l] = new Option (cats[what][i],cats[what][i]);
if (in_array (cats[what][i], beenSelected)==1) obj.options[l].selected = true;
obj.options[l].id = cats[what][i];
if (typeof optionsArr[what]=='undefined') optionsArr[what] = new Array ();
l++;
}
beenSelected is created successfully using PHP. It writes a JS array to the script with the list of selected options which had been selected when the form was submitted.
The problem
Somehow, calling "in_array (cats[what][i], beenSelected)" (even if just in an alert) creates an infinite loop on the page and it spits out infinite options which are selected... in_array is returning 0 though...
Any thoughts?
retValue = 0;
for (i=0;i < arrToSearch.length;i++) {
if (arrToSearch[i] == string){
retValue = 1;
break;
}
}
return retValue;
}
That checks to see if an element exists in an array. Returns 0 on false, 1 on true.
Now, I use it when making my options like this:
l = obj.options.length;
for (i=0;i<cats[what].length;i++){
obj.options[l] = new Option (cats[what][i],cats[what][i]);
if (in_array (cats[what][i], beenSelected)==1) obj.options[l].selected = true;
obj.options[l].id = cats[what][i];
if (typeof optionsArr[what]=='undefined') optionsArr[what] = new Array ();
l++;
}
beenSelected is created successfully using PHP. It writes a JS array to the script with the list of selected options which had been selected when the form was submitted.
The problem
Somehow, calling "in_array (cats[what][i], beenSelected)" (even if just in an alert) creates an infinite loop on the page and it spits out infinite options which are selected... in_array is returning 0 though...
Any thoughts?