Arun Arun - 11 months ago 63
jQuery Question

Select2 plugin multiple selects only first value from array

I am using

plugin in my project.

When I dynamically add values to the
select as array, it only shows the first value from the array.


<select multiple id="selId" name="selId[]" required>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4">D</option>
<option value="5">E</option>


$(function() {
$("#selId").select2('val', [1, 2]);

I want to make select the 1st and 2nd options.

What I am missing?

I created a fiddle explains the same Here

Please give suggestions. Any help could be appreciated

Answer Source

You can try something like this :

$(function() {