R
Ravi Singh (UCSD)
Hello all
Attached is a simple HTML file that adds and delete rows. In the add
row function I set an attribute "onClick" this triggers the
testMessage() function. When I try this in Firefox it works just fine
however on IE it just refuses to work.
What is interseting is the ROW that already exists has a similar
'onClick' event which works when the page is loaded, but subsequent
"row" additions to the table to not work in IE.
Much thanks for any helfull insights that you can give.
-Ravi Singh.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Testing DOM insertions</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT type=text/javascript>
var info = new Array("TD 1: index 0", "TD 2: index 1", "TD 3: index
2");
function insertTR(){
var newTR = document.createElement("tr");
newTR.setAttribute('onclick', "testMessage(this)");
for (i=0;i<info.length; i++)
{
var newTD= document.createElement("TD");
var newText = document.createTextNode(info);
newTD.appendChild(newText)
newTR.appendChild(newTD);
}
var tbElm =
document.getElementById("table1").getElementsByTagName("TBODY")[0];
tbElm.appendChild(newTR);
// }
}
function deleteTR()
{
var tbl = document.getElementById('table1');
var lastRow = tbl.rows.length;
if (lastRow > 0)
tbl.deleteRow(lastRow - 1);
else
alert("No more rows left to delete!");
}
function testMessage(oRow) {
alert(oRow);
}
</SCRIPT>
<META content="MSHTML 6.00.2900.2627" name=GENERATOR></HEAD>
<BODY>
<TABLE id=table1 border=1><TBODY>
<TR onClick="testMessage(this)"><TD>TD 1: index 0</TD>
<TD>TD 2: index 1</TD>
<TD>TD 3: index 2</TD></TR>
</TBODY></TABLE>
<P><INPUT onclick=insertTR(); type=button value="Insert Row">
<INPUT onclick=deleteTR(); type=button value="Delete Row"></P>
</BODY></HTML>
Attached is a simple HTML file that adds and delete rows. In the add
row function I set an attribute "onClick" this triggers the
testMessage() function. When I try this in Firefox it works just fine
however on IE it just refuses to work.
What is interseting is the ROW that already exists has a similar
'onClick' event which works when the page is loaded, but subsequent
"row" additions to the table to not work in IE.
Much thanks for any helfull insights that you can give.
-Ravi Singh.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Testing DOM insertions</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT type=text/javascript>
var info = new Array("TD 1: index 0", "TD 2: index 1", "TD 3: index
2");
function insertTR(){
var newTR = document.createElement("tr");
newTR.setAttribute('onclick', "testMessage(this)");
for (i=0;i<info.length; i++)
{
var newTD= document.createElement("TD");
var newText = document.createTextNode(info);
newTD.appendChild(newText)
newTR.appendChild(newTD);
}
var tbElm =
document.getElementById("table1").getElementsByTagName("TBODY")[0];
tbElm.appendChild(newTR);
// }
}
function deleteTR()
{
var tbl = document.getElementById('table1');
var lastRow = tbl.rows.length;
if (lastRow > 0)
tbl.deleteRow(lastRow - 1);
else
alert("No more rows left to delete!");
}
function testMessage(oRow) {
alert(oRow);
}
</SCRIPT>
<META content="MSHTML 6.00.2900.2627" name=GENERATOR></HEAD>
<BODY>
<TABLE id=table1 border=1><TBODY>
<TR onClick="testMessage(this)"><TD>TD 1: index 0</TD>
<TD>TD 2: index 1</TD>
<TD>TD 3: index 2</TD></TR>
</TBODY></TABLE>
<P><INPUT onclick=insertTR(); type=button value="Insert Row">
<INPUT onclick=deleteTR(); type=button value="Delete Row"></P>
</BODY></HTML>