SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing child nodes for a select list

    I have tried all these methods to remove all the options from a dropdown list
    Code:
    	selObj.removeChild.childNodes;	
    	selObj.removeChild.firstChild;
    	selObj.removeChild.childNodes(1);
    	selObj.removeAttributeNode.nodeName("C");
    	selObj.removeNode.childNodes;
    What is the proper method? I want to remove all options...

    Thanks,
    Ryan
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, got this to work:

    Code:
    var selObj = document.getElementById("DEFECT_5");
    for(i = 0; i<=selObj.length; i++){
    	selObj.remove(selObj.options[i]);
    }
    -Ryan
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    northern Maine
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var range = document.createRange();
    range.selectNodeContents(refToSelectElement);
    range.deleteContents();
    range.detach();
    Is how you would do it with DOM2 most efficiently. Naturally though, only Gecko-based browsers have this level of support, so a DOM1 based solution:

    Code:
    while (refToSelectElement.hasChildNodes())
      refToSelectElement.removeChild(refToSelectElement.lastChild);
    Jason - Contact Me
    Supermoderator @ CodingForums

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.


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
  •