I
irixdude
I am trying to create a script to enter the values of an array into a
dynamically generated table 3 columns wide. I have a counter for the
row # that I am using to name/id the row TR node so I an attach 3
cells (3 columns) before attaching the full row to the table. I'm not
sure where the problem is, but in its current form my script doesn't
even generate the first node before stopping with an error. 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);
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>
dynamically generated table 3 columns wide. I have a counter for the
row # that I am using to name/id the row TR node so I an attach 3
cells (3 columns) before attaching the full row to the table. I'm not
sure where the problem is, but in its current form my script doesn't
even generate the first node before stopping with an error. 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);
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>