views:

44

answers:

1

In mootools 1.2, getting selected options in a multi select is easy using getSelected:

// code 1
$('my_select').getSelected().each(function(opt) { 
    // stuff
});

Is there an equivalent of that in mootools 1.1 or do I have to use getChildren() and check whether it has been selected?

What I have at the moment:

// code 2
// get all options
$('my_select').getChildren().each(function(g) {
    // if option is selected
    if(g.selected == true)
    {
       // do some stuff
    }
});
+1  A: 

$('my_select').getSelected() is in 1.2.4 right? Not sure if it's 1.1. if not you can try

$$('#my_select option').filter(function(option){ return option.selected; })

If filter does not exist, to bad. :( you have to do it manually...

sheeks06
If i understand correctly, the end result is similar to what I have in code snippet number 2 above. Which is not what I'd expected. I was hoping to get only the selected items without having to loop through each option.
superspace
well, if getSelected is not there. i'm afraid we have no choice. atleast filter returns an array. so you can still chain it to .each
sheeks06