[highlight #FF99FF]I am creating a table dynamically from an XML file in the DOM. The intent is to create a new <img src= attribute from the hrefs in the XML file 2006_Print_List.xml(See bottom of thread for XML).[/highlight]
[highlight]-I am able to get the filenames from the DOM(See Test Button), but I can't get the [!]imageFilename1by1[/!] variable to load when creating the HTML table. What am I missing?[/highlight]
Any help you can provide would be great!
<html>
<head>
<title>Sample Product Gallery</title>
<script language="JavaScript" type="text/JavaScript">
<!--
//Load the XML to buffer
{ var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
xmldoc.async=false;
xmldoc.load("2006_Print_List.xml");
xmldoc.setProperty("SelectionLanguage", "XPath");}
//Creates Parent Nodes as a Variable
PrintNode = xmldoc.childNodes[2].selectNodes('./Print');
//Creates All image filenames as Variable
allImgFilenames = xmldoc.childNodes[2].selectNodes('./Print/file/@href');
//-->
</script>
<script>
[!]function srcLoop(){
for (var currentNodeNum = 0; currentNodeNum <= 10; currentNodeNum++){
var imageFilename1by1 = ("images/" + PrintNode[currentNodeNum].childNodes[4].getAttribute("href"))
alert("imageFilename1by1 is " + imageFilename1by1)
}
}[/!]
function start() {
// get the reference for the body
var mybody = document.getElementsByTagName("body")[0];
// creates a <table> element and a <tbody> element
mytable = document.createElement("table");
mytablebody = document.createElement("tbody");
// creating all cells
for(var j = 0; j < 2; j++) {
// creates a <tr> element
mycurrent_row = document.createElement("tr");
for(var i = 0; i < 3; i++) {
// creates a <td> element
mycurrent_cell = document.createElement("td");
//creates img tag
imgTag = document.createElement("img");
//appends img tag to table data node
mycurrent_cell.appendChild(imgTag)
//Sets src attribute to filename variable
imgTag.src = imageFilename1by1;
// creates a text node
currenttext = document.createTextNode("cell is row "+j+", column "+i);
// appends the text node we created into the cell <td>
mycurrent_cell.appendChild(currenttext);
// appends the cell <td> into the row <tr>
mycurrent_row.appendChild(mycurrent_cell);
}
// appends the row <tr> into <tbody>
mytablebody.appendChild(mycurrent_row);
}
// appends <tbody> into <table>
mytable.appendChild(mytablebody);
// appends <table> into <body>
mybody.appendChild(mytable);
// sets the border attribute of mytable to 2;
mytable.setAttribute("border", "0");
}
</script>
</head>
<body onload="start();srcLoop()">
<input type="button" value="Test imageFilename1by1 Variable" onclick="srcLoop()"></input>
</body>
</html>
--------------------
XML
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Printlist.xsl"?>
<PrintList>
<Print>
<ID>001000</ID>
<PrintName>Farmhouse in Spring</PrintName>
<Season>spring</Season>
<PrintSize>8x10</PrintSize>
<file href="spring_234farm.jpg"></file>
<Desc></Desc>
</Print>
<Print>
<ID>001000</ID>
<PrintName>Mr. Bunny</PrintName>
<Season>spring</Season>
<PrintSize>4x6</PrintSize>
<file href="spring_easter_bunny_small.jpg"></file>
<Desc></Desc>
</Print>
</PrintList>
[highlight]-I am able to get the filenames from the DOM(See Test Button), but I can't get the [!]imageFilename1by1[/!] variable to load when creating the HTML table. What am I missing?[/highlight]
Any help you can provide would be great!
<html>
<head>
<title>Sample Product Gallery</title>
<script language="JavaScript" type="text/JavaScript">
<!--
//Load the XML to buffer
{ var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
xmldoc.async=false;
xmldoc.load("2006_Print_List.xml");
xmldoc.setProperty("SelectionLanguage", "XPath");}
//Creates Parent Nodes as a Variable
PrintNode = xmldoc.childNodes[2].selectNodes('./Print');
//Creates All image filenames as Variable
allImgFilenames = xmldoc.childNodes[2].selectNodes('./Print/file/@href');
//-->
</script>
<script>
[!]function srcLoop(){
for (var currentNodeNum = 0; currentNodeNum <= 10; currentNodeNum++){
var imageFilename1by1 = ("images/" + PrintNode[currentNodeNum].childNodes[4].getAttribute("href"))
alert("imageFilename1by1 is " + imageFilename1by1)
}
}[/!]
function start() {
// get the reference for the body
var mybody = document.getElementsByTagName("body")[0];
// creates a <table> element and a <tbody> element
mytable = document.createElement("table");
mytablebody = document.createElement("tbody");
// creating all cells
for(var j = 0; j < 2; j++) {
// creates a <tr> element
mycurrent_row = document.createElement("tr");
for(var i = 0; i < 3; i++) {
// creates a <td> element
mycurrent_cell = document.createElement("td");
//creates img tag
imgTag = document.createElement("img");
//appends img tag to table data node
mycurrent_cell.appendChild(imgTag)
//Sets src attribute to filename variable
imgTag.src = imageFilename1by1;
// creates a text node
currenttext = document.createTextNode("cell is row "+j+", column "+i);
// appends the text node we created into the cell <td>
mycurrent_cell.appendChild(currenttext);
// appends the cell <td> into the row <tr>
mycurrent_row.appendChild(mycurrent_cell);
}
// appends the row <tr> into <tbody>
mytablebody.appendChild(mycurrent_row);
}
// appends <tbody> into <table>
mytable.appendChild(mytablebody);
// appends <table> into <body>
mybody.appendChild(mytable);
// sets the border attribute of mytable to 2;
mytable.setAttribute("border", "0");
}
</script>
</head>
<body onload="start();srcLoop()">
<input type="button" value="Test imageFilename1by1 Variable" onclick="srcLoop()"></input>
</body>
</html>
--------------------
XML
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Printlist.xsl"?>
<PrintList>
<Print>
<ID>001000</ID>
<PrintName>Farmhouse in Spring</PrintName>
<Season>spring</Season>
<PrintSize>8x10</PrintSize>
<file href="spring_234farm.jpg"></file>
<Desc></Desc>
</Print>
<Print>
<ID>001000</ID>
<PrintName>Mr. Bunny</PrintName>
<Season>spring</Season>
<PrintSize>4x6</PrintSize>
<file href="spring_easter_bunny_small.jpg"></file>
<Desc></Desc>
</Print>
</PrintList>