Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript 4th Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning JavaScript 4th Edition
This is the forum to discuss the Wrox book Beginning JavaScript, 4th Edition by Paul Wilton, Jeremy McPeak; ISBN: 978-0-470-52593-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 4th Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 18th, 2011, 05:22 PM
Authorized User
Points: 222, Level: 4
Points: 222, Level: 4 Points: 222, Level: 4 Points: 222, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2007
Location: Phoenix, AZ, USA.
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
Default variable not being initialized in for loop condition

Hi,

I'm trying to work Example 11 in chapter 12.

When the code reaches the for loop, the variable is not being initialized.

Here is the code:

<code>
function displayDogs()
{
var dogNodes = xmlDocument.getElementsByTagName("dog");

var table = document.createElement("table");
table.setAttribute(
"cellPadding",5);
table.setAttribute(
"width","100%");
table.setAttribute(
"border", "1");

var tableHeader = document.createElement("thead");

for (var i = 0; i < dogNodes[0].childNodes.length; i++)
{
var tableRow = document.createElement("tr");
var currentNode = dogNodes[0].childNodes[i];

if (currentNode.nodeType == 1)
{
var tableHeaderCell = document.createElement("th");

var textData = document.createTextNode(currentNode.nodeName);

tableHeaderCell.appendChild(textData);
tableRow.appendChild(tableHeaderCell);
}
}

tableHeader.appendChild(tableRow);

table.appendChild(tableHeader);

var tableBody = document.createElement("tbody");

for (var i = 0; i < dognodes.length; i++) <===========
{
var tableRow = document.createElement("tr");

for (var j = 0; j < dogNodes[i].childNodes.length; j++)
{
var currentNode = dogNodes[i].childNodes[j];
if (currentNode.nodeType == 1)
{
var tableDataCell = document.createElement("td");
textData =
document.createTextNode(currentNode.firstChild.nod eValue);

tableDataCell.appendChild(textData);

tableRow.appendChild(tableDatacell);
}
}

tableBody.appendChild(tableRow);
}

table.appendChild(tableBody);

document.body.appendChild(table);
}
</code>

Any help ...


Tom
__________________
Thomas G Magaro
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT:How to loop through nodes and retrieve attributes values based on some condition smandeh XSLT 2 March 24th, 2009 01:50 PM
How can I take variable value in for loop Swetha XSLT 3 May 1st, 2008 06:17 AM
Problem with variable in test condition bartnowa XSLT 3 December 20th, 2007 06:31 AM
dynamic session variable in while loop ashuphp Beginning PHP 0 May 3rd, 2007 04:59 AM
To iterate the FOR loop variable garg.ashish15 Oracle 0 November 10th, 2006 08:31 AM



All times are GMT -4. The time now is 07:38 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.