[Project_owners] [XUL&JS] Cant remove from listbox?
Michael Vincent van Rantwijk, MultiZilla
mv_van_rantwijk at yahoo.com
Wed Aug 15 12:16:04 PDT 2007
Foreningen Selvet - Jesper Staun Hansen wrote:
> 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");
>>> }
>> Don't use the "in" iterator which breaks when someone adds methods.
>>
> Provide another example if any.
Don't use: for (var key in items) {
but: for (var i=0; i < items.length; i++) {
because for...in iterates also over user defined properties in addition
to the array elements, and your items var is... or should be an array in
your code (property .selectedItems normally returns an array).
--
Michael Vincent van Rantwijk
- MultiZilla Project Team Lead
- XUL Boot Camp Staff member
- iPhone Application Developer
More information about the Project_owners
mailing list