Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap multiselect get selected values

How do I get back on onChange all selected values in my multiselect dropdown. Used plugin here. Trying to use the following but I think I'm on the wrong track

$('#multiselect1').multiselect({         selectAllValue: 'multiselect-all',         enableCaseInsensitiveFiltering: true,         enableFiltering: true,         maxHeight: '300',         buttonWidth: '235',         onChange: function(element, checked) {             var brands = $('#multiselect1 option:selected');             var selection = [];             $(brands).each(function(index, brand){                 selection.push(brand);             });              console.log(selection);         }     }); 

found it

$('#multiselect1').multiselect({     selectAllValue: 'multiselect-all',     enableCaseInsensitiveFiltering: true,     enableFiltering: true,     maxHeight: '300',     buttonWidth: '235',     onChange: function(element, checked) {         var brands = $('#multiselect1 option:selected');         var selected = [];         $(brands).each(function(index, brand){             selected.push([$(this).val()]);         });          console.log(selected);     } }); 
like image 319
fefe Avatar asked Dec 11 '13 10:12

fefe


People also ask

How do you display a selected value in the bootstrap multiple dropdown from the database?

1st. take all venue_id`s in array & remove duplicate values, then by mappint this array with $venue display option... 2nd . to display selected values... check new venue id array with venue in <option> tag if it is equal then echo selected..

How do I get the selected value of MultiSelect dropdown in JQuery?

With jQuery, you can use the . val() method to get an array of the selected values on a multi-select dropdown list.


2 Answers

the solution what I found to work in my case

$('#multiselect1').multiselect({     selectAllValue: 'multiselect-all',     enableCaseInsensitiveFiltering: true,     enableFiltering: true,     maxHeight: '300',     buttonWidth: '235',     onChange: function(element, checked) {         var brands = $('#multiselect1 option:selected');         var selected = [];         $(brands).each(function(index, brand){             selected.push([$(this).val()]);         });          console.log(selected);     } });  
like image 141
fefe Avatar answered Sep 19 '22 01:09

fefe


Shorter version:

$('#multiselect1').multiselect({     ...     onChange: function() {         console.log($('#multiselect1').val());     } });  
like image 28
vl.lapikov Avatar answered Sep 21 '22 01:09

vl.lapikov