SOLVED: Javascript DOM removeChild

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
The Monkey
Forum Contributor
Posts: 168
Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA

SOLVED: Javascript DOM removeChild

Post by The Monkey »

Hello DevNetwork :),

I am attempting to create an AJAX application which gathers form data, ships it off to the server, extracts the data from the returned XML file and updates the labels of the input fields according to the result (updated successfully, invalid email address, password length must be at least 6 characters, etc).

7 seconds after the label is updated, however, I want it reset to its original state. Thus, I think I need to un-append (remove) the appended child, but my attempts at doing so have failed.

Code: Select all

if ( document.getElementById(id) != null ) /* id is the id of the label of the input field that was validated */
{			
	/* this basically _appends_ an input field's label. For instance, the label for the password field could have &quote;updated successfully&quote; appended. */
	document.getElementById(id).appendChild( document.createTextNode( ' - ' + response.childNodesїi].firstChild.data ) );
}

[code="Javascript:Reset the Label to it's original state"]function clear()
{
	tags = document.formsї'account'].getElementsByTagName('label');
	
	for ( var i = 0; i < tags.length; i++ )
	{
		/* This is where I am TOTALLY lost */
		document.getElementById( tagsїi].getAttribute('id') ).parentNode.removeChild( document.getElementById( tagsїi].getAttribute('id') ).childNodesї0] );
	}
}

[quote="Error message returned by Firefox's JavaScript Console"]Error: uncaught exception: [Exception... "Node was not found"  code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)"  location: *censored* Line: 78][/quote]

Line 78 is the line after /* This is where I am TOTALLY lost */.

What do I need to do to remove the appended data from the label?
Last edited by The Monkey on Wed Jul 20, 2005 9:19 pm, edited 1 time in total.
The Monkey
Forum Contributor
Posts: 168
Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA

Post by The Monkey »

What is it about typing your problem out that lets you solve it on your own 10 minutes later?

The solution: remove parentNode from the clear() function, line 8 in the code I posted.

That's what I get for programming with code I don't understand. :)
Post Reply