Forum Moderators: open

Message Too Old, No Replies

netscape and table insertRow()

sorta works

         

f00sion

8:07 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



I have this code just on a test page and it works great in IE but in NS it only 'sorta' works..

<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>&nbsp;</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?

BlobFisk

2:57 pm on Jan 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi f00sion,

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";

Works for IE and Opera etc. (but not for Mozilla/Netscape),

But:


myTD.innerText="Some Inner Text";

Works for Mozilla/Netscape (but not IE/Opera)!

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

f00sion

1:23 am on Jan 21, 2004 (gmt 0)

10+ Year Member



that works perfectly!..but now I have another problem, the page where the button is will be contained in an iframe within the page that has the table on it... in IE this works fine:
myTR=parent.myTable.insertRow(0);
but in NN, no such luck..how do I access the objects in the parent frame?

BlobFisk

10:49 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try:

myTR=parent.oneTable.insertRow(0);

or

myTR=window.parent.oneTable.insertRow(0);

HTH