Hi - I have a function which appends row(s) to the bottom of a table:
The button within the(se) row(s) allows the user to repeatedly insert "nested" row(s) in between:
My problem is I want a function that deletes the last added row executed by "mouseUpHandler " and all the "nested" cells related to that "parent" cell (but not any "nested cells of earlier "parent" cells). My problem is that the value required by deleteRow varies every time this delete command is executed.
I have tried to circumvent this by naming all "nested" cells (and their corresponding rows) the same is their "parent" row. But I cannot figure out how to delete multiple rows (or cells) that have the same ID.
Any suggestions?
Thanks!
Code:
function mouseUpHandler() {
var table = document.getElementById("mytable");
var rowCount = table.rows.length;
var addRow = table.insertRow(rowCount);
addRow.id = cnt;
var addCell = addRow.insertCell(1);
addCell.id = cnt;
addCell.colSpan = 3;
var element = document.createElement("input");
element.type="button";
element.value="Add fixed component";
element.onclick=function(){
addComponent(this)
}
addCell.appendChild(element);
}
Code:
function addComponent(nSel)
{
var nrowIndex = nSel.parentNode.parentNode.rowIndex;
var addRow = document.getElementById('mytable').insertRow(nrowIndex+1);
addRow.id = nSel.parentNode.id;
var addCell = addRow.insertCell(0);
addCell.id = nSel.parentNode.id;
addCell.colSpan = 3;
addCell.innerHTML = 'Component:';
}
I have tried to circumvent this by naming all "nested" cells (and their corresponding rows) the same is their "parent" row. But I cannot figure out how to delete multiple rows (or cells) that have the same ID.
Any suggestions?
Thanks!
Comment