xxxxxxxxxx
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());
xxxxxxxxxx
//get all selected select object
$('#select2Id').find(':selected');
//get all selected value
$("#select2Id").select2("val");
xxxxxxxxxx
var selectedValuesTest = ["WY", "AL", "NY"];
$(document).ready(function() {
$("#e1").select2({
multiple: true,
});
$('#e1').val(selectedValuesTest).trigger('change');
});
select2 get selected value text multiple
xxxxxxxxxx
// get select2 selected options html elements here
var selector = `${elementId} :selected`;
let arrayOfValues = []; // will be [{ name: "text", _id: "val" }]
// iterate all selected answers and add their values and text to the result
$(selector).each(function (i, selected) {
var $selected = $(selected);
one.ref_values.push({ name: $selected.text(), _id: $selected.val() });
});