Get Selected value from Multi-Value Select Boxes by jquery-select2?

Kaps Hasija picture Kaps Hasija · Oct 15, 2012 · Viewed 137k times · Source

I am using Select2 Jquery to bind my dropdown which is used for multiple selection . I am using select2 jquery.

It's working fine, I can bind my dropdown but I need to get the selected value from my multi-value selector. I am looking for method to get value which is supported by select2 Jquery. it might be having a function get selected value.
my drop down binding code

$(".leaderMultiSelctdropdown").select2( {
    maximumSelectionSize: 4
});

Answer

Manuel Schweigert picture Manuel Schweigert · Oct 15, 2012
alert("Selected value is: "+$(".leaderMultiSelctdropdown").select2("val"));

alternatively, if you used a regular selectbox as base, you should be able to use the normal jquery call, too:

alert("Selected value is: "+$(".leaderMultiSelctdropdown").val());

both return an array of the selected keys.