How to remove items of a select field

Discussion in 'Javascript' started by sniper, Sep 19, 2006.

  1. sniper

    sniper Guest

    Hi all;
    i'm adding items to a select list like this:

    var insertPoint = inst.getElementsByTagName("itemlist").item(0);
    var itemCount = insertPoint.getElementsByTagName("item").length;
    for(x=0;x<found.length;x++)
    {
    alert(found[x])
    var item = document.createElementNS("", "item")
    item.appendChild(document.createTextNode(found[x]))
    insertPoint.appendChild(item)
    }

    Now if i want to delete all items of this select list how to do it?
    thanks for your help
     
    sniper, Sep 19, 2006
    #1
    1. Advertising

  2. sniper

    Paul Guest

    sniper wrote:
    > Hi all;
    > i'm adding items to a select list like this:
    >
    > var insertPoint = inst.getElementsByTagName("itemlist").item(0);
    > var itemCount = insertPoint.getElementsByTagName("item").length;
    > for(x=0;x<found.length;x++)
    > {
    > alert(found[x])
    > var item = document.createElementNS("", "item")
    > item.appendChild(document.createTextNode(found[x]))
    > insertPoint.appendChild(item)
    > }
    >
    > Now if i want to delete all items of this select list how to do it?
    > thanks for your help


    The code to work with here is a bit sparce but, I'll have a go at it
    anyway. (BTW, is this xforms?)
    var insertPoint = inst.getElementsByTagName("itemlist").item(0);
    var items = insertPoint.getElementsByTagName("item");
    for( i=0; i<items.length; i++)
    {
    insertPoint.removeChild(items);
    }

    ref: http://developer.mozilla.org/en/docs/DOM:element.removeChild
     
    Paul, Sep 19, 2006
    #2
    1. Advertising

  3. sniper

    sniper Guest

    sniper, Sep 19, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keiron Waites
    Replies:
    1
    Views:
    127
    Keiron Waites
    Oct 21, 2003
  2. Gumtree
    Replies:
    3
    Views:
    270
    Matt Kruse
    Nov 10, 2004
  3. Notgiven
    Replies:
    8
    Views:
    127
    Notgiven
    Aug 7, 2006
  4. Sound
    Replies:
    2
    Views:
    481
    Randy Webb
    Sep 28, 2006
  5. Beholder
    Replies:
    3
    Views:
    137
    Beholder
    Jan 22, 2007
Loading...

Share This Page