473,947 Members | 18,894 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Just wondering...

I've been reading the DHTML Reference (2nd edt.) book by Danny Goodman.
I've come to a point in the book where my scripting experience isn't
that great to understand some of the coding examples and was just
wondering if anyone could help.

I'm at chapter 5 section 'Dynamic Tables' this is the example I'm a
little confused with...

function drawTable(tbody ) {
var tr, td, i, j, oneRecord;
tbody = document.getEle mentById(tbody) ;
// node tree
var data = xDoc.getElement sByTagName("sea son")[0];
// for td class attributes
var classes = ["ctr","","","", "ctr"];
for (i = 0; i < data.childNodes .length; i++) {
// use only 1st level element nodes
if (data.childNode s[i].nodeType == 1) {
// one bowl record
oneRecord = data.childNodes[i];

tr = tbody.insertRow (tbody.rows.len gth);

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("number")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("year")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("winner")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("loser")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("winscore")[0].firstChild.nod eValue + "
- " +
oneRecord.getEl ementsByTagName ("losscore")[0].firstChild.nod eValue;
}
}
}

Obviously this function draws a table and fills the cells with content
from an XML doc this line from the function is where I'm getting
confused:

td.setAttribute ("class",classe s[tr.cells.length-1]);

Why is there a -1 in the Statement?

Aug 21 '06 #1
2 1392
DoomedLung wrote:
I've been reading the DHTML Reference (2nd edt.) book by Danny Goodman.
I've come to a point in the book where my scripting experience isn't
that great to understand some of the coding examples and was just
wondering if anyone could help.

I'm at chapter 5 section 'Dynamic Tables' this is the example I'm a
little confused with...

function drawTable(tbody ) {
var tr, td, i, j, oneRecord;
tbody = document.getEle mentById(tbody) ;
// node tree
var data = xDoc.getElement sByTagName("sea son")[0];
// for td class attributes
var classes = ["ctr","","","", "ctr"];
for (i = 0; i < data.childNodes .length; i++) {
// use only 1st level element nodes
if (data.childNode s[i].nodeType == 1) {
// one bowl record
oneRecord = data.childNodes[i];

tr = tbody.insertRow (tbody.rows.len gth);

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("number")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("year")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("winner")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("loser")[0].firstChild.nod eValue;

td = tr.insertCell(t r.cells.length) ;
td.setAttribute ("class",classe s[tr.cells.length-1]);
td.innerHTML =
oneRecord.getEl ementsByTagName ("winscore")[0].firstChild.nod eValue + "
- " +
oneRecord.getEl ementsByTagName ("losscore")[0].firstChild.nod eValue;
}
}
}

Obviously this function draws a table and fills the cells with content
from an XML doc this line from the function is where I'm getting
confused:

td.setAttribute ("class",classe s[tr.cells.length-1]);

Why is there a -1 in the Statement?
Because array indexes start at zero. He is getting the element of
"classes" that corresponds to the last cell of the row.

Aug 21 '06 #2
Hey, thanks for your speedy rely! Makes sense now :)

Cheers

Aug 21 '06 #3

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

Similar topics

11
2242
by: Steven Burn | last post by:
Just wondering if it would be possible to convert an existing e-mail form to; 1. Send the e-mail (as it does now...without problems) 2. Copy one folder on the server, to another new folder Using the username from the e-mail form, as the new foldername? --
2
1984
by: KevinGPO | last post by:
Just wondering if anyone knows if there are converters to convert from: MS Visual C++ 6.0 or MS Visual Studio 2003 project files into UNIX autogen/configure/make files?
13
3184
by: jm | last post by:
I am trying to use datepart to get the real name of the month like "April" or "APR" not just "4." I could not find it in the documentation. Sorry. Thank you.
8
2191
by: MLH | last post by:
A97 HELP shows the proper syntax for using Nz as Nz(variant) I'm wondering what to expect from potential past misuse I've made. For example, consider the following... Private Sub Command0_Click() Dim a As Long, b As String b = Nz(a, "") MsgBox b End Sub
3
1009
by: rodchar | last post by:
hey all, i was wondering why I've seen articles similar to the following: ADO.NET Code Generator - Map DataBase Objects To .NET Classes What does this subject accomplish? Like, this does this instead of doing what? Please also give me an anology if possible. thanks,
16
1092
by: rodchar | last post by:
Hello all, Please allow me to revisit this topic once more it has hindered me for the longest. Even after the great replies I got in the past. I guess they might have been a bit over my head or my requirements weren't very clear. I’m betting on the latter (not asking clear) so after several months of pondering please allow me to rephrase my question. Ok, so I'll begin already Given: Northwind Customers and Orders tables. Goal1 I'd...
8
1028
by: rodchar | last post by:
hey all, i'm using method webclient.filedownload to automatically download a file from an internet site. that works great. well i was wondering if there was a way to monitor or check if that file has changed since the last time it was downloaded? thanks, rodchar
5
4026
Nert
by: Nert | last post by:
hi, I've created a website, uhhmmn something like posting/uploading images and videos.., i made my site working well, i save images on database but the videos are just copied from the client folder to the folder on my server, the only thing i save is the url of the video so that i can able to display it using the <embed> tag. Now i'm just wondering if it is possible to save a video on mysql database? If it's not can anyone give me a...
42
2101
by: lorlarz | last post by:
Contrary to what one authority in the JavaScript field says: JavaScript does make errors when dealing with just with integers. This authority (Douglas Crockford.) says: "integer arithmetic in floating point is exact" Well, I can prove this is incorrect with this program: http://mynichecomputing.com/digitallearning/yourOwn.htm This a program that uses only integers, yet comes up short in its
0
9985
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
11173
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...
0
10694
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7431
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
6118
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
6336
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4948
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
4540
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3544
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.