By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

for loop broken!

P: n/a
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="+gl obalData[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);
}
}

Aug 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
Phuff wrote:
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="+gl obalData[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);
}
}
Aug 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.