Forum Moderators: open
<script>
function insertRow()
{
var oneTable = document.getElementById("myTable")
var myTR = oneTable.insertRow(1)
myTR.className = "blah"
created row!
var myTD=myTR.insertCell();
myTD.innerText="blah";
}
</script>
<table id="myTable" border="1">
<tr><td> </td></tr>
</table>
<form>
<input type="button" name="foo" value="new row" onClick="javascript:insertRow();">
</form>
In netscape each time you click the button it moves the table down some like its adding the row but without the cell... any ideas?
Ok - there are 2 things here!
Firstly, you need to specify a cell number to create:
var myTD=myTR.insertCell(0);
Secondly (and here is where it gets messy), you need to do the same thing twice! Why?
Because:
myTD.innerHTML="Some Inner Text";
But:
myTD.innerText="Some Inner Text";
So, the full solution is:
var myTD=myTR.insertCell(0);
//NEED TO SPECIFY A CELL NUMBER TO INCLUDE
myTD.innerHTML="Some Inner Text";
//FOR IE/OPERA
myTD.innerText="Some Inner Text";
//FOR MOZILLA
Note: The order of innerHTML and innerText is important!
HTH