deleteRow leaves empty <TR></TR> pairs

J

John Geddes

In both IE6 and Netscape 7:

insertRow method of tbody is behaving as expected:
- inserts a new row
- increases tbody.rows.length

BUT deleteRow is not doing the opposite.

It DOES delete the row, but it adds a <TR></TR> pair just before the
</TBODY> and that leaves the tbody.rows.length count unchanged.

Demo page at http://www.btinternet.com/~geddes.winster/drtable.htm

What am I doing wrong?

John Geddes
 
V

Vjekoslav Begovic

John Geddes said:
In both IE6 and Netscape 7:

insertRow method of tbody is behaving as expected:
- inserts a new row
- increases tbody.rows.length

BUT deleteRow is not doing the opposite.

It DOES delete the row, but it adds a <TR></TR> pair just before the
</TBODY> and that leaves the tbody.rows.length count unchanged.

Demo page at http://www.btinternet.com/~geddes.winster/drtable.htm

Snippet of your code:
function delRow(tabName){
var thisBody=document.getElementById(tabName);
var origLength=thisBody.rows.length;
var tr= thisBody.insertRow(thisBody.rows.length); //Why this?
var rowNo=document.aForm.t1.value;
if (thisBody.rows[rowNo]){
thisBody.deleteRow(rowNo);
var tb2=document.getElementById(tabName);
alert("attempted to delete row index="+ rowNo+ " from
"+tabName+String.fromCharCode(10)+"rowCount changed from "+origLength+" to
"+thisBody.rows.length+String.fromCharCode(10)+"CHECK length with redefined
tbody: "+tb2.rows.length);
} else {
alert("no row in "+tabName+"with index "+rowNo);
}
}
Try get rid of statement:

var tr= thisBody.insertRow(thisBody.rows.length);
 
J

John Geddes

Looks like I copied the addRow script and forgot to kill that line.

Must be spending too long staring at the screen.

Thanks so much.

John Geddes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top