I am developing a form with several multiselects. For this, I use the Select2 library.
$(".chosen-select").select2({
allow_single_deselect: true,
width: "150px"
});
......
<select id="ship2" class="chosen-select" data-placeholder="Select vessel">
<option></option>
<option value="value1">title1</option>
<option value="value2">title2</option>
</select>
The problem is that when I try to get the selected values, they are returned in the order in which they are indicated in the element <select>, and not in the order in which they were selected:
var selectedDayPorts = $('#ship2');
var dayPorts = selectedDayPorts.select2("val");
Is there a way to get them in the correct order?
source
share