removeChild

I am making a function to remove some elements, the user clicks on a check-box and the a function removes all elements that are checked, I am able to retrieve all the ids of the elements to be removed and store them in an array so I can then do something like this:


document.getElementById(form_values[0]).removeChild(document.getElementById(ids[i]));

But that is not working for me.

I have checked and ids does contain all the elements ids to be removed

I get an exemption in firebug


uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLFormElement.removeChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost/clms/libraries/connect/calli_modules/calli_forms/form_create.php# :: group_selected_items :: line 411" data: no]

function group_selected_items(){
	var grouped_items = document.getElementById(form_values[0]).getElementsByTagName('a');
	var ids = [];
	for (var i = 0; i < grouped_items.length; i++){
		if (grouped_items[i].className === 'checkbox checkbox_c') {
			ids[i] = grouped_items[i].parentNode.parentNode.id;
		}
	}
	for (var i = 0; i < ids.length; i++){
		//alert(ids[i]);
		document.getElementById(form_values[0]).removeChild(document.getElementById(ids[i]));
	}
}

I guess I was doing more than needed, I fixed it with this:

function group_selected_items(){
	var grouped_items = document.getElementById(form_values[0]).getElementsByTagName('a');
	for (var i = 0; i < grouped_items.length; i++){
		if (grouped_items[i].className === 'checkbox checkbox_c') {
			document.getElementById(form_values[0]).removeChild(document.getElementById(grouped_items[i].parentNode.parentNode.id));
		}
	}
}

Any ideas on how I can make it better?