This is link to the root of my question:
JQuery UI Multiselect how to get selected options values.
The problem was how to get :selected from the multiselect widget made by Michael Aufreiter.
There is also this solution to the problem:
$('.ui-multiselect .selected li').each(function(idx,el){
var link = $(el).data('optionLink');
if(link) {
selFriends.push(link.val()); //array with selected items
}
});
But I’m going to add a second multiselect block with the same data. This means that $('.ui-multiselect .selected li') will get :selected elements from both widgets. That’s wrong and I don’t know how to modify code above. For example, I have two select blocks with different IDs, how can I make jQuery recognize from where is the element?
As final target: I need to push selected elements from first widget to selFriends array and selected elements from the second to anotherArray. Any ideas?
There are more simple way to get selected values, if you are using that multiselect widget
In example, if you have element
<select id="countries" class="multiselect" multiple="multiple" name="countries[]">...</select>(like the example in link), you can get selected values like this: