[thelist] DOM, removing rows fun

Tom Dell'Aringa pixelmech at yahoo.com
Mon Sep 30 17:41:01 CDT 2002


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.

My guess is maybe to remove the rows at the end - except I'm not sure
how to store all the rows until the end and then delete those. Either
that or somehow I have to adjust my loop..any suggestions?

Function:
---------------------------------------------
function tempDelete()
{
	var table = document.getElementById("mydocs");
	var tbody = document.getElementById("doclist");
	var numrows = table.getElementsByTagName("TR").length;
	x = 0;

	while(x < numrows)
	{
		if(!x == 0)
		{
		curID = table.getElementsByTagName("TR").item(x).id;
		CBID = "cb_" + curID;
		curCB = document.getElementById(CBID);

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

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com



More information about the thelist mailing list