Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript 4th Edition
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 18th, 2011, 06:22 PM
Authorized User
 
Join Date: Dec 2007
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





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 07: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 09:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.