473,811 Members | 2,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why do numbers work, but variables don't in this array?

Ok, here's my dumbdumb question of the day:

I have this loop that's supposed to loop through the 11 XML elements named
"title" in the object.

When I put a number in the array brackets like this:

tables = response.getEle mentsByTagName( "title");

for(var i = 0;i <= tables.length;i ++) {
strTitles = strTitles + tables[1].firstChild.nod eValue+"<br/>";
}

document.getEle mentById('foo') .innerHTML = strTitles;

....I get the appropriate value displayed (albeit 11 times).

But when I try to put in the variable "i", like this:

tables = response.getEle mentsByTagName( "title");

for(var i = 0;i <= tables.length;i ++) {
strTitles = strTitles + tables[i].firstChild.nod eValue+"<br/>";
}

document.getEle mentById('foo') .innerHTML = strTitles;

....I get the following error:

Error:tables[i] has no properties?

Any clue why? I'm sure when I hear the answer I'll be kicking myself, but
I have to know. :)
--
[=============== =============== =============== =============== =============== ==]
Sugapablo -> http://www.sugapablo.net
[=============== =============== =============== =============== =============== ==]

Nov 4 '05 #1
3 1161


Sugapablo wrote:

for(var i = 0;i <= tables.length;i ++) {


for (var i = 0; i < tables.length; i++) {
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 4 '05 #2
Sugapablo wrote:
Ok, here's my dumbdumb question of the day:

I have this loop that's supposed to loop through the
11 XML elements named "title" in the object.

When I put a number in the array brackets like this:

tables = response.getEle mentsByTagName( "title");
So there is no Array involved in this question at all then? The -
getElementsByTa gName - method returns an object implementing the -
NodeList - interface.

Incidentally, it is distinctly odd to name a variable "tables" and
assign a reference to a - NodeList - of TITLE elements to that
variable.
for(var i = 0;i <= tables.length;i ++) {
You have recognised that javascript tends to use zero-based Arrays,
collections, etc. That is true of the - NodeList - interface as well.
But the - length - property of such objects is the number of elements
they contain and so includes the object at index zero. You should
iterate to - i < tables.length - because there will be no element at
index tables.length.
strTitles = strTitles + tables[1].firstChild.nod eValue+"<br/>";
}

document.getEle mentById('foo') .innerHTML = strTitles;

...I get the appropriate value displayed (albeit 11 times).
You have 11 TITLE elements in the same document?
But when I try to put in the variable "i", like this:

tables = response.getEle mentsByTagName( "title");

for(var i = 0;i <= tables.length;i ++) {
strTitles = strTitles + tables[i].firstChild.nod eValue+"<br/>";
}

document.getEle mentById('foo') .innerHTML = strTitles;

...I get the following error:

Error:tables[i] has no properties?
When - i - equals the - length - of the - NodeList - there is no element
at - tables[i] -.
I'm sure when I hear the answer I'll be kicking myself, ...


Yes, you will. ;)

Richard.
Nov 4 '05 #3
On Fri, 04 Nov 2005 19:17:25 +0000, Richard Cornford wrote:
When - i - equals the - length - of the - NodeList - there is no element
at - tables[i] -.
I'm sure when I hear the answer I'll be kicking myself, ...


Yes, you will. ;)


Yes, I am. (*explitive*)

Thanks!
--
[=============== =============== =============== =============== =============== ==]
Sugapablo -> http://www.sugapablo.net
[=============== =============== =============== =============== =============== ==]

Nov 4 '05 #4

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

Similar topics

2
2200
by: SabMan | last post by:
I understand that document.layers is no longer supported in Netscape 7.1 but I am not sure on how to fix the code so that it will work with Netscape 7.1. I understand that document.all is no longer supported in IE6 but I am not sure on how to fix the code so that it will work with IE6. <!--
4
10769
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group consisting of 6 numbers - with a total of 50 groups of numbers. A well-known girl that some publishing companies use to provide introductory level textbooks to various Junior Colleges in the U.S., not surprisngly, asks for this same exact...
17
7469
by: Steve Jorgensen | last post by:
If you've ever employed custom error numbers and messages in you programs, you've probably ended up with code similar to what I've ended up with in the past something like... <code> public Const xyzcErrNumBase As Long = 500 Public Const xyzcErrNumHeyDontDoThat = xyzcErrNumBase + 1 Public Const xyzcErrTxtHeyDontDoThat = "Hey! Don't do that!"
17
12796
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
6
4906
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
60
1950
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers ending in 5 ..which obviously cannot be prime numbers) can anyone please help me out with the reason?? /*Generate Prime Numbers*/ #include<stdio.h>
3
4388
by: mjaaland | last post by:
Hi, I hope someone can help me out with this one! Step 1: I get a struct from unmanaged code looking like this. public unsafe struct KEY { public UInt16 idkey_len; public byte* idkey; }
0
9722
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
9603
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,...
1
10393
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
9200
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
5550
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...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.