...

View Full Version : Dynamic Table with HTML Cells



seshav
07-23-2010, 07:45 PM
Hi All,

I tried to add links to open local xml files in browser in a dynamic table cells. I need help. I tried all ways but I think I miss something.
I can open them without table just by document.write(xmlfile location).
Here is my code. please help.

function showResultsTable(searched, srchedname) {
// get the reference for the body
var mybody = document.getElementsByTagName("body")[0];

// creates a <table> element and a <tbody> element
mytable = document.createElement("table");
mytable.setAttribute('id', 'resulttable');
mytablebody = document.createElement("tbody");

// creating all cells
var mycurrent_cell = new Array();

for(var j = 0; j < srchedname.length; j++) {
// creates a <tr> element
mycurrent_row = document.createElement("tr");

mycurrent_cell[0] = document.createElement("td");
currenttext = document.createTextNode(j);
mycurrent_cell[0].appendChild(currenttext);
mycurrent_row.appendChild(mycurrent_cell[0]);


mycurrent_cell[1] = document.createElement("td");
link = document.createElement("a");
link.name = ""+srchedname[j]);
link.href = "C:\\AAA\\TestCasesList.xml";
mycurrent_cell[1].appendChild(link);
mycurrent_row.appendChild(mycurrent_cell[1]);

mycurrent_cell[2] = document.createElement("td");
currenttext = document.createTextNode(searched[j]);
mycurrent_cell[2].appendChild(currenttext);
mycurrent_row.appendChild(mycurrent_cell[2]);

// 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", "2");

}

Old Pedant
07-23-2010, 10:11 PM
DEBUG DEBUG DEBUG!!!!

Use Firebug plugin with Firefox.

You have AT LEAST one major error:


link.name = ""+srchedname[j])

You have a ) but no ( in that line.

There may be other errors. You'll never know unless you debug.

Old Pedant
07-23-2010, 10:20 PM
I *think* this is what you were trying to achieve:


<html>
<head>
<script>
function showResultsTable(searched, srchedname) {
// get the reference for the body
var mybody = document.getElementsByTagName("body")[0];

// creates a <table> element and a <tbody> element
var mytable = document.createElement("table");
mytable.setAttribute('id', 'resulttable');
var mytablebody = document.createElement("tbody");

// creating all cells
var mycurrent_cell = new Array();

for(var j = 0; j < srchedname.length; j++) {
// creates a <tr> element
var mycurrent_row = document.createElement("tr");
var cell;

cell = document.createElement("td");
var currenttext = document.createTextNode(j);
cell.appendChild(currenttext);
mycurrent_row.appendChild(cell);

cell = document.createElement("td");
link = document.createElement("a");
link.name = srchedname[j];
link.href = "C:\\AAA\\TestCasesList.xml";
var currenttext = document.createTextNode(searched[j]);
link.appendChild(currenttext);
cell.appendChild(link);
mycurrent_row.appendChild(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", "2");

}
</script>
</head>
<body>
<form><input type=button value="click" onclick="showResultsTable(['abc','def','ghi'],['foo','bar','baz']);"/></form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum