...

View Full Version : Adding to SELECT works in NS6 but not IE6



wac
10-11-2002, 11:47 PM
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
}
}
}

lpok
10-14-2002, 07:39 AM
The add method in IE takes a number as a second parameter. So change

target.add(option, tgtBefore);

into

target.add(option, 0);

wac
10-14-2002, 03:04 PM
That did it! Thanx muchly (Thank you very much)

xioan
01-08-2009, 09:20 PM
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:mad: X(
}


}

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

itsallkizza
01-11-2009, 05:52 AM
http://codingforums.com/showthread.php?t=154407



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum