...

View Full Version : help appending nodes



jaserlet
04-30-2008, 12:32 AM
Hello, I am trying to create a script that will put the contents of an array into a dynamically generated table 3 columns wide. In this case, a really simple example that will insert the numbers "one" thru "six" (actually 7 in the array, but I don't yet have a case for the final incomplete row). For some reason I can't even get the first cell attached to the first row. Please let me know what I'm doing wrong.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">
function startup()
{
colcount = 0;
rowcount = 0;
var List = new Array('one','two','three','four','five','six','seven');
var Count = 7;
tabBody=document.getElementsByTagName("TBODY").item(0);
for (var i = 0; i<Count; i++)
{
if (colcount == 0)
{
var row=document.createElement("TR");
rowcount++;
row.id = rowcount;
}
cell = document.createElement("TD");
textnode=document.createTextNode(List[i]);
cell.appendChild(textnode);
document.getElementById(rowcount).appendChild(cell);
colcount++;
if (colcount == 3)
{
tabBody.appendChild(row);
colcount = 0;
}
}
}
</script>
</head>
<body onload="startup()">
<table border='1' id='mytable'>
<tbody>
</tbody>
</table>
</body>
</html>

Philip M
04-30-2008, 08:48 AM
document.getElementById( "mytable" ).appendChild(cell);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum