Add a new cell as the table is created

wxdqz

New Member
To make a long story short, I need to dynamicaly add a new cell to a table if certain conditions are met. The cell must be added as the table is created not after it is created. I created a simplified version and will paste it below. The function executes properly when the "3" cell is clicked but for some reason it doesn't execute as the table is created. Any help would be appreciated. I would paste a link but it is on an intranet.

Thanks

<html>
<head>
<title>Untitled Document</title>
<script>
var counter = 7;
function addCell( that )
{
newItem = document.createElement( "td" );
newCell = that.insertAdjacentElement( "BeforeBegin", newItem );
newCell.innerHTML = counter;
counter++;
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table border="1">
<tr>
<td>1</td>
<td>2</td>
<td onClick="addCell( this );">3
<script>addCell( this );</script>
</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
</body>
</html>
 
Top