473,507 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

for loop broken!

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
1 1272
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2315
by: z0ink | last post by:
I am working on a small graphing application. In the process of graphing I use 3 seperate scripts for getting the job done. The first is the page that the use sees and selects all the data from. ...
21
2038
by: Steven Bethard | last post by:
Can someone point me to the documentation on what's supposed to happen when you use the "for x in X:" syntax when X does not have an __iter__ method? I know that the code: >>> class S: .... ...
32
3765
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
43
5528
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
21
18651
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
2
2660
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
63
3153
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
0
1472
by: Mark Harrison | last post by:
HOWTO: Integrating Posgresql queries into an event loop. Mark Harrison mh@pixar.com May 27, 2004 Problem ------- The commonly used postgresql APIs will block until completed.
73
4536
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
16
1744
by: Andy B | last post by:
I have the following code inside of a WebBrowser.DocumentCompleted event: For index As Integer = 0 To Me.Browser.Document.GetElementsByTagName("ul").Item(0).GetElementsByTagName("li").Count ...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.