[thelist] DOM, removing rows fun

Means, Eric D eric.d.means at boeing.com
Mon Sep 30 17:45:01 CDT 2002


-----Original Message-----
From: Tom Dell'Aringa [mailto:pixelmech at yahoo.com]
Sent: Monday, September 30, 2002 5:40 PM
To: thelist at lists.evolt.org
Subject: [thelist] DOM, removing rows fun

> I'm dynamically adding/removing rows in a table with the DOM. The
> function below checks to see if the checkbox in the particular row is
> checked - if it is, it whacks the row.
>
> The function works fine as far as removing the row. The problem is
> that once that happens, it throws the while loop off, because the
> number of rows has *changed* since I removed one.

If you delete the row, don't increment the loop counter (or possibly
decrement the limit condition, but I'd try not incrementing first).

			if(curCB.checked == true)
			{
				row =
table.getElementsByTagName("TR").item(x);
				tbody.removeChild(row);
				x = x - 1; // decrement x to counter the x =
x + 1 below
			}
		}
		x = x + 1;

OR
			if(curCB.checked == true)
			{
				row =
table.getElementsByTagName("TR").item(x);
				tbody.removeChild(row);
				numrows = numrows - 1;
			}
		}
		x = x + 1;



More information about the thelist mailing list