SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: removeChild

Hybrid View

  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code JavaScript:
    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

    Code:
    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]
    Code JavaScript:
    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]));
    	}
    }

  2. #2
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I guess I was doing more than needed, I fixed it with this:

    Code JavaScript:
    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?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •