Jelle
Jelle

Reputation: 1060

How to get selected items with Chosen JQuery plugin?

I'm using chosen for my multiple select box, but I don't know how to get the selected items?

  <select class="multiselect" multiple="" name="parlementId">           
        @foreach (Politicus p in politici)
        { 
            <option value="@p.politicusID">@Html.DisplayName(p.Account.voornaam.ToString())</option>
        }

  </select> 

  $('.multiselect').chosen({ width: '500px', allow_single_deselect: true, max_selected_options: 5 });

  $('.multiselect').on('change', function (evt, params) {
       //this is where I need to know which options are selected
  });

Upvotes: 0

Views: 2981

Answers (1)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62498

you can get like this:

var values = $(".multiselect").chosen().val();
// this will give you values in an array

See Documentation here

or:

 var values = $(".multiselect").val();

Upvotes: 4

Related Questions