Forum Moderators: open

Message Too Old, No Replies

Dynamically add rows..

Dynamically add rows..

         

sireesha

9:16 am on Dec 22, 2003 (gmt 0)

10+ Year Member



I want to dynamically add rows to a table.I have the code for IE but I want the code which works on Netscape too.Any pointers to this would be appreciable.

The following script works in IE.
<script language="javaScript">
var d=document.all;
function addRows()
{
var length=d.mainTable.rows.length;
var a = d.mainTable.insertRow();
var b = a.insertCell(0);
b.innerHTML=d.subTable.innerHTML;
}
</script>

Thanks,
Sireesha

Purple Martin

12:29 am on Dec 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The key is how you reference objects. IE and Netscape do it differently, so you need to have two bits of code (one for each browser).

At the moment you're doing it the IE way with document.all which is fine.

You also need to do it the Netscape way which uses document.getElementById

Use some browser sniffing code to determine which browser the user has (there are lots of sample scripts available for browser sniffing) and then use an if statement to either do it the IE way or the Netscape way.