Click to See Complete Forum and Search --> : something wrong with iteration


JACKWEBS
June 3rd, 2008, 06:34 AM
Can anyone see anything wrong with this excerpt of code.
When I use alert(workingstructurewithdivid.length);
I get 111 but it only seems to be going through the code once and stopping

Edit: I'm getting an 'undefined' is null or not an object error but it only comes up some of the time so something in the checks must be null and causes it to fall over. Any ideas how to check?


else if (document.getElementById("Division").value >= 1) {
for (i = 0; i < workingstructurewithdivid.length; i++) {
var optn = document.createElement("OPTION");
optn.text = workingstructurewithdivid[i].substring(0,5);
optn.value = workingstructurewithdivid[i];
alert(i);
alert ("DIV:" + document.getElementById("Division").value);
alert (optn.value.substring(6,7));
if ((document.getElementById("Division").value == optn.value.substring(6,7))
&& optn.text != workingstructurewithdivid[i-1].substring(0,5)) { //dup check
document.getElementById("BusUnitLevels").options.add(optn);
}
}
}

PeejAvery
June 3rd, 2008, 09:25 AM
It's hard to tell without more working code. We can't test it out.