I am updating select list option on onchange event. That means if an option is selected in dropdwon1 I want to hide that particular option in other remaining dropdowns. This feature is already achieved in general html select but unable to achieve it in select2. My code which is working for general select.
var d_array = Array();
$(document).ready(function(){
$('.mselect').on("change", function (e) {
d_array = [];
$('.mselect').each(function(k,v){
cv = $(this).val();
if($.trim(cv) != '')
{
d_array.push(cv);
}
});
checkMSelect2();
$('.select2').select2();
});
});
function checkMSelect2()
{
$('.mselect').each(function(k,v){
c = $(this);
cv = c.val();
c.find('option').show();
$(d_array).each(function(ki, vi){
if(vi != cv)
{
c.find('option[value="'+vi+'"]').hide();
}
});
});
}
Ask if you need any further explanation.