for loop broken!

P

Phuff

Am I going crazy? My for loop is incrementing one too far. Never seen
this before. On the test job I'm doing there are 10 items in the
globalData array (index 0-9). How, then, is the index getting to 10?!
Of course I'm getting "undefined" errors because there is nothing at
10!

This would be the same as
for(i=0;i<10;i++)
{
ERROR no index at 10...well duh! I didn't say <=10 I said <10
}


So is this a javascript problem or an IE issue?

Here's the code:

function checkReports()
{
//create the XMLHttp object
for(var j=0;j<globalData.length;j++)
{
var oXmlHttp = createXMLHttp();
var path =
"http://localhost/step1/include/panelDetailsFunctions.asp?checkRep=true&quote="+globalData[j].quote+"&unit="+globalData[j].Unit;
oXmlHttp.open("GET", path, true);

oXmlHttp.onreadystatechange = function(){
if (oXmlHttp.readyState == 4){
var data =oXmlHttp.responseText;
var div =
document.getElementById("repErr-"+globalData[j].Unit);
//div.innerHTML = data;
alert(data);
}
};
oXmlHttp.send(null);
}
}
 
P

Phuff

UPDATE:

Okay, duh!!! This method would have worked great on a synchronous
call. Since I'm doing asynchronous by the time the return call comes
back the index counter is at ten. I'm guessing it evaluated just fine,
like my hundreds of other loops, that I just didn't see the error until
it had returned. It did not shoot off a request at 10 but exited the
loop, however the index was still left at 10 where it obviously left
the loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top