473,666 Members | 1,991 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<globalDat a.length;j++)
{
var oXmlHttp = createXMLHttp() ;
var path =
"http://localhost/step1/include/panelDetailsFun ctions.asp?chec kRep=true&quote ="+globalDat a[j].quote+"&unit=" +globalData[j].Unit;
oXmlHttp.open(" GET", path, true);

oXmlHttp.onread ystatechange = function(){
if (oXmlHttp.ready State == 4){
var data =oXmlHttp.respo nseText;
var div =
document.getEle mentById("repEr r-"+globalDat a[j].Unit);
//div.innerHTML = data;
alert(data);
}
};
oXmlHttp.send(n ull);
}
}

Aug 29 '06 #1
1 1276
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<globalDat a.length;j++)
{
var oXmlHttp = createXMLHttp() ;
var path =
"http://localhost/step1/include/panelDetailsFun ctions.asp?chec kRep=true&quote ="+globalDat a[j].quote+"&unit=" +globalData[j].Unit;
oXmlHttp.open(" GET", path, true);

oXmlHttp.onread ystatechange = function(){
if (oXmlHttp.ready State == 4){
var data =oXmlHttp.respo nseText;
var div =
document.getEle mentById("repEr r-"+globalDat a[j].Unit);
//div.innerHTML = data;
alert(data);
}
};
oXmlHttp.send(n ull);
}
}
Aug 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2327
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. This selected data gets passed internally using session variables to the next page. This page takes the passed data, runs it for error checking and determines where to send it next. I have gotten most of the desired results through this method...
21
2061
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: .... def __len__(self): return 42 .... def __getitem__(self, i): return i .... >>> for x in S(): .... print x
32
3805
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
5575
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 fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in a loop, they either terminate, or repeat themselves. In the mythical halting problem scenario...
21
18712
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 nanosleep(), depending on platform }
2
2678
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 across some wierd loop behavior. With the pasted code I receive the output that follows. I realize that the code is broken, because the inner loop fails to reset j for each iteration of the outer loop (the fix is commented out). I also know that...
63
3153
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
0
1498
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
4594
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 endless loop in a line with: if a==b: print 'OK' I mean, it would be of much help to me on my way to understanding Python to know how such prefix code leading to an endless loop can look like and if it is eventually not possible to write such...
16
1755
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 NotesList.Items.Add(Me.Browser.Document.GetElementsByTagName("ul").Item(0).GetElementsByTagName("li").Item(index).InnerText) Next index
0
8445
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.