Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NS_ERROR_XPC_BAD_CONVERT_JS with removelChild()

Status
Not open for further replies.

abraxas

Programmer
Jan 15, 2001
75
AU
Hi there,
This error appears while iterating through <input> tags. Once a condition is satisfied a call to removeChild() is made. It is this call that produces error

NS_ERROR_XPC_BAD_CONVERT_JS in firefox 2.0

Code fragment follows
var objInputs = document.getElementsByTagName("input"); // get all input tags
var con = document.getElementById('AddCallReport'); // parent container holding everything aka form id
Code:
	for (var i = 0; i < objInputs.length; i++)
	{
                // lets avoid the controls shall we
		if (objInputs[i].type == "button" || objInputs[i].type == "reset")
			continue;

		//
		// Now test for certain string instances in identity attribute
		// and remove them
		if ((objInputs[i].id.toString().indexOf("$$PK_") != -1) || (objInputs[i].id.toString().indexOf("$$Qty_") != -1))
		{
			
			var strId = objInputs[i].id.toString();
			var aVar = con.removeChild(strId);
		}
	}
The indexOf methods seem to be satisfied since when there are no id's containing "$$PK_", the error is not produced. The items searched for by indexOf show up in DOM Inspector and are direct children of the con object.

I googled around for a few hours and found a plethora of different circumstances that the error is produced, but nothing along these lines.

The idea of this is to reset a form after a xhr call but i suppose a location.href(self) would be more simple.
Any ideas
Many thanks in advance
 
Once you have removed the child, you change the objInputs.length value and will end up skipping a node. Try decreasing the loop when you remove the node:
Code:
...
            var aVar = con.removeChild(strId);
            [!]loop--;[/!]
...

It's not going to help you with your problem I don't think [smile]

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
This is how you do, eliminating all the irrelevance and errors and making it much more generic. Watch the difference yourself.
[tt]
var objInputs = document.getElementsByTagName("input");
for (var i=objInputs.length-1;i>-1;i--) {
if ((objInputs.type != "button" && objInputs.type != "reset") &&
(objInputs.id.indexOf("$$PK_") != -1) || (objInputs.id.indexOf("$$QTY_") != -1)) {
objInputs.parentNode.removeChild(objInputs);
}
}
[/tt]
 
Thanks tsuji,
That cleared up several such instances of that error message, had no idea that removeChild accepted an object, thought it was a damn string primitive!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top