multiselect checkbox dropdown
41,523
You can use buttonText
option of multiselect.
$('#lstStates').multiselect({
buttonText: function(options, select) {
console.log(select[0].length);
if (options.length === 0) {
return 'None selected';
}
if (options.length === select[0].length) {
return 'All selected ('+select[0].length+')';
}
else if (options.length >= 4) {
return options.length + ' selected';
}
else {
var labels = [];
console.log(options);
options.each(function() {
labels.push($(this).val());
});
return labels.join(', ') + '';
}
}
});
Author by
Maddy
Updated on July 09, 2022Comments
-
Maddy almost 2 years
I am using multiselect checkbox dropdown.
Please look example jsfiddle
$(function () { $('#lstStates').multiselect({ }); });
Once you select states it show then TEXT value and concat with comma like: New Jersey, New York, Ohio
But I want VALUE of that selected ITEM like: NJ, NY, OH
-
Ersin Basaran almost 9 yearsjust make sure that you remove
console.log
statements if you don't use console-polyfill or similar.