Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Multiselect : How to know which value was selected/deselected

I have Multiselect dropdown. Whenever there is a select or deselect, I need to get the value. I am using change event, but struggling to get which option was selected/deselected.

like image 928
Bads123 Avatar asked Nov 02 '22 15:11

Bads123


1 Answers

//all options

var all=[];
$('#multiple').each(function(i, selected){ 
    all[i] = $(selected).text(); 
});

//selected options  
var foo = []; 
$('#multiple :selected').each(function(i, selected){ 
    foo[i] = $(selected).text(); 
});

// unselected options
var de= $.grep(all, function(element) {
    return $.inArray(element, foo) !== -1;
});

In the foo array are the selected values

In the de array are the unselected values

like image 171
Rituraj ratan Avatar answered Nov 17 '22 10:11

Rituraj ratan