Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Adding to SELECT works in NS6 but not IE6

    I'm coding a javascript listpair where you select entries in one list,
    click the arrow, and the items are moved from the source list to the target list. I use the 'name' field to locate the SELECT list.
    In NS6, the following code works fine. In IE6, it fails
    near the line marked. Does anyone have an idea why?
    Where can I find the DOM properites and functions for IE?
    I've been using the W3C references, but clearly IE must
    be doing something different (as usual).

    function moveListSelection(src, tgt)
    {
    source = document.getElementsByName(src)[0] ;
    if (source == null) return ;

    target = document.getElementsByName(tgt)[0] ;
    if (target == null) return ;
    /*
    * Move all selected options in source to the target
    * note that if we start from 0, the remove will
    * reorder subsequent items, so we start from the
    * end of the source list.
    */
    tgtBefore = null ;
    for (i=source.length-1; i>=0; i--)
    {
    option = source.options.item(i) ;
    if (option.selected)
    {
    source.remove(i) ;
    target.add(option, tgtBefore) ; // **IE quits here!! why?
    tgtBefore = option ; // add next item before this one
    }
    }
    }
    Wayne Christian

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The add method in IE takes a number as a second parameter. So change

    target.add(option, tgtBefore);

    into

    target.add(option, 0);

  • #3
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up

    That did it! Thanx muchly (Thank you very much)
    Wayne Christian

  • #4
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I write this code:
    function addToGroup(){
    groupSelected = document.getElementById('idslibresG');
    groupsusers = document.getElementById('idsgrupoUSG');
    indiceGS = groupSelected.selectedIndex;
    if(groupsusers.options.length>0)
    {if(groupsusers.options[0].value==-1)
    groupsusers.options[0] = null;//borro el elemento vacio
    if(groupSelected.options[0].value==-1)
    groupSelected.options[0] = null;//borro el elemento vacio
    }
    try
    {
    groupsusers.add(groupSelected.options[indiceGS],null); // standards compliant
    }
    catch(ex)
    {
    groupsusers.add(groupSelected.options[indiceGS]); // IE only X(
    }


    }

    the line with the face, it gets an error in IE6, says
    argument not valid, cod. 0
    why??

  • #5
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  

    Posting Permissions

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