Hi everyone,

Many thanks for looking. Here's the problem.

I have a form with three option buttons. Depending on what one the user clicks on I need a particular div to be shown, while the other two divs are to be removed.

The only problem is that the removeChild doesn't work. I have worked on this for 3 or four hours now and can't find a solution. Any help would be great as I'm not so hot with javascript.

Here's the code that I need to tweak.

function removeElement_old(REMOVE_DIV){
	var d = document.getElementById('sidebar');
	var d_nested = document.getElementById(REMOVE_DIV);
	if (d_nested.parentNode == d) { 
		alert("Removed div "+ d_nested.id);
		alert("Did not remove div " + d_nested.id);	
}//Closing function

function removeElement(parentDiv, childDiv){
     if (childDiv == parentDiv) {
          alert("The parent div cannot be removed.");
     else if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
     else {
          alert("Child ("+childDiv+") div has already been removed or does not exist.");
          return false;

function switchToDiv(DIV){
	alert("Div being passed in is: "+DIV);
	var packageWrite = "";
	var hotelWrite = "";
	var flightWrite = "";
	if ( DIV == 'package' ){
		packageWrite = "<p>Package shown</p>";
		document.getElementById(DIV).innerHTML = packageWrite; 
	else if ( DIV == 'hotel'){
		hotelWrite = "<p>hotel shown</p>";
		document.getElementById(DIV).innerHTML = hotelWrite;
	else if( DIV == 'flight'){
		flightWrite = "<p>flight shown</p>";
		document.getElementById(DIV).innerHTML = flightWrite;
		alert('No search cat selected');
		return false;	

}//closing function

So just to explain the code a bit. I call the switchToDiv function from my HTML. Depending on what I pass in, a specific div is shown. Except that only works for the first item picked. Once I pick an item any more choices after that do not work.

The two functions at the top are two different approaches to me trying to solve the problem.

Many thanks.

Use the Error Console feature of Firefox to track down Javascript errors. Use the Firebug extension of Firefox for debugging Javascript application. Also don't search for parent elements of node, just use the parentNode property of the Node.


Thanks for the tips. I'll give them a shot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.