Select2 get all values
http://stackoverflow.com/questions/16187672/how-to-get-all-the-values-in-a-select2-dropdown
HTML
<script src="http://ivaynberg.github.io/select2/select2-master/select2.js"></script>
<link rel="stylesheet" href="http://ivaynberg.github.io/select2/select2-master/select2.css">
<input type="text" width="40" id="individualsfront" name="individualsfront" style="width:240px" value="" data-spy="scroll" />
JavaScript
var preload_data = [
{ id: 'user0', text: 'Disabled User', locked: true}
, { id: 'user1', text: 'Jane Doe'}
, { id: 'user2', text: 'John Doe', locked: true }
, { id: 'user3', text: 'Robert Paulson', locked: true }
, { id: 'user5', text: 'Spongebob Squarepants'}
, { id: 'user6', text: 'Planet Bob' }
, { id: 'user7', text: 'Inigo Montoya' }
];
$(document).ready(function () {
var results = [];
$("#individualsfront").select2({
multiple: true,
query: function (query){
var data = {results: []};
$.each(preload_data, function(){
if(query.term.length == 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0 ){
data.results.push({id: this.id, text: this.text });
}
});
results = data;
query.callback(data);
}
});
$('#individualsfront').on('open',function(){
console.log("click");
$(".select2-result-label").each(function()
{
console.log($(this).text());
})
});
});