I use Chosen jQuery plugin on a multiple select element.
I want to retrieve and to display the options value in the order they were selected (clicked).
For example, if I click on "Three", "Two" then "One", I should get the values in this order: [3, 2, 1]
I use the 'change' event of Chosen but it gives me the values ordered as they are declared in the DOM. i.e.: [1, 2, 3]
Here is my code snippet:
<select class="chosen" data-order="true" name="multiselect[]" id="multiselect" multiple="true">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
<div id="result"></div>
<script type="text/javascript" src="jquery-1.11.0.js"></script>
<script type="text/javascript" src="chosen.jquery.min.js"></script>
<script type="text/javascript">
$(".chosen").chosen({enable_search_threshold: 10}).change(function(event) {
if(event.target == this) {
var value = $(this).val();
$("#result").text(value);
}
});
</script>
jsFiddle demo: http://jsfiddle.net/FjET4