like this?
Main Topics
Browse All TopicsI have a dynamic table with tr ids set as below as an example.
<Table name = "tblGrid">
<tr id=1>
<Td></td>
</tr>
<tr id=2>
<Td></td>
</tr>
<tr id=3>
<Td></td>
</tr>
<tr id=4>
<Td></td>
</tr>
</table>
I then have a array which determines which row ids need deleting eg (1,2,3)
In order to do this i loop through the table rows. If the table row matches the array item to be deleted it is deleted. The problem is the table rows go out of synch once it is deleted.
For example :
Looping through array(1,2,3)
Array item 1
TR 1 ArrayItem(1) TR1 equals ArrayItem(1) so delete Row 1
TR 2
TR 3
TR 4
Array item 2 I want to delete TR(2) but the loop now counts to TR3 as this is the 2nd item in the loop
TR 2
TR 3
TR 4
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here is a complete example for you. Works with IE/FF
Hope this works for you.
<tr> is a child of <tbody>
<html>
<head>
<title>Delete Row From a Table - Pravin Asar</title>
<style type="text/css">
</style>
<script language="javascript">
function DeleteRowFromTable(tableId
var table = document.getElementById(ta
if (!table) { return ; }
var tbody = table.getElementsByTagName
if (!tbody) { return; }
var delRow = document.getElementById(ro
alert ('Deleting Row ID: ' + delRow.id);
if (!delRow) { return; }
tbody[0].removeChild(delRo
}
</script>
</head>
<body>
<table id= "tblGrid">
<tr id="1">
<Td>Row1 Cell1</td>
<Td>Row1 Cell2</td>
<Td>Row1 Cell3</td>
<Td><a href="#" onclick="DeleteRowFromTabl
</tr>
<tr id="2">
<Td>Row2 Cell1</td>
<Td>Row2 Cell2</td>
<Td>Row2 Cell3</td>
<Td><a href="#" onclick="DeleteRowFromTabl
</tr>
<tr id="3">
<Td>Row3 Cell1</td>
<Td>Row3 Cell2</td>
<Td>Row3 Cell3</td>
<Td><a href="#" onclick="DeleteRowFromTabl
</tr>
<tr id="4">
<Td>Row4 Cell1</td>
<Td>Row4 Cell2</td>
<Td>Row4 Cell3</td>
<Td><a href="#" onclick="DeleteRowFromTabl
</tr>
</table>
</body>
</html>
I managed to fix this myself
The trick is to create an array of row ids before you loop through the table deleting rows. Then you can loop through this array deleting rows not worrying about the ids going out of synch
// create array of row ids to delete
var ids = "";
var tbl = document.getElementById('t
var lastRow = tbl.rows.length - 1;
for (i = 0; i < lastRow; i++) {
if (i > 0) {
IDval = parseInt(tbl.rows[i].id, 0);
ids = ids + "," + IDval;
}
}
Business Accounts
Answer for Membership
by: HonorGodPosted on 2009-03-16 at 06:11:48ID: 23897260
Remember that indexing is zero origin.
The 1st row is row[ 0 ], etc.