Click here to Skip to main content
15,905,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,
I use select2 plugin fro use multiple selection dropdownlist with textbox.
Now there is problem to get all selected values. It returns only first selected value. Give me some tips regarding this.
Posted
Comments
JoCodes 20-Jan-14 9:43am    
What you tried so far and where are you stuck?

1 solution

Most multiple selection boxes have both a second set of 'Selected' properties. SelectedItems, SelectedValues etc. which give you all the selected items.

Edited:
I did a little search on select2 and this is what showed up. The question this was answering appeared to be very similar to the one you asked here.

Option 1:

var results = [];
$("#individualsfront").select2({
    multiple: true,
    query: function (query){
        var data = {results: []};
        $.each(yuyu, 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.results; //<=====  
        query.callback(data);
    }
});


$('#individualsfront').on('open',function(){
    $.each(results, function(key,value){
        console.log("text:"+value.text);
    });
});



Option 2:

C#
$('#individualsfront').on('open',function(){
    $(".select2-result-label").each(function()
        {
            console.log($(this).text());
        })
    });
});
 
Share this answer
 
v2
Comments
pkvartej7121 18-Jan-14 2:44am    
There not any type of SelectedItems or SelectedValues properties
bowlturner 20-Jan-14 9:03am    
I found some code that might help. Added it to the solution.
pkvartej7121 31-Jan-14 7:33am    
thank you very much my friend.
bowlturner 31-Jan-14 10:16am    
no problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900