[Project_owners] [XUL&JS] Cant remove from listbox?
Foreningen Selvet - Jesper Staun Hansen
jesper at selvet.dk
Wed Aug 15 11:27:34 PDT 2007
Michael Vincent van Rantwijk, MultiZilla wrote:
> 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.
>
Provide another example if any.
>
>> 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);
>
Wont work with removeItemAt as it always starts with 0 even it I select
7, 9 and 16, then it would remove 0, 1, 2.
More information about the Project_owners
mailing list