[Project_owners] [XUL&JS] Cant remove from listbox?

Michael Vincent van Rantwijk, MultiZilla mv_van_rantwijk at yahoo.com
Wed Aug 15 11:01:31 PDT 2007


Foreningen Selvet - Jesper Staun Hansen wrote:
> I have the following code:
> 
>      function movetolist(fromlistid, tolistid) {
>    var from = document.getElementById(fromlistid);
>    var to = document.getElementById(tolistid);
>    dump("I am running! On these: "+from.selectedItems+"\n");
>    var items = from.selectedItems;
>    for(var key in items) {
>        dump("Would add: "+key+"\n");
>    }
>      for(var i=0; items.length > i; i++) {
>        dump("I will add: "+items[i].getAttribute('value')+" from: "+ 
> fromlistid +" to: "+ tolistid +" key: "+i+"\n");
>        
> to.appendItem(items[i].getAttribute('label'),items[i].getAttribute('value')); 
> 
>        items[i].removeItem;     }
>    }
> 
> 
> 
> This dumps the following when running:
> I am running! On these: [object XULElement]
> Would add: 0
> Would add: max
> I will add: networth from: notshow to: doshow key: 0
> 
> 
> Now the first for loop does it all wrong, and will always take the very 
> first listitem in the listbox.

Don't use the "in" iterator which breaks when someone adds methods.

> The other for loop does it right and adds the one listitem to another 
> listbox. But! I cant remove it from the original listbox again...
> How do i remove it from the originating listbox?

Try .removeItemAt(index);

-- 
Michael Vincent van Rantwijk
- MultiZilla Project Team Lead
- XUL Boot Camp Staff member
- iPhone Application Developer



More information about the Project_owners mailing list