0

I have a query that if user select options in multi select box(choosen plugin) it should post to another page the order which was selected by user.

For e.g. I have following code

<select name="city" multiple data-rel=​"chosen" >
<option value="1">Mumbai</option>
<option value="2">Pune</option>
<option value="3">Nagpur</option>
<option value="4">Nashik</option>
</select>

If user select in following order Nagpur,Pune,Nashik and Mumbai it is posting values to another page by following manner 1.2,3,4( sorted).

But, I would like to post to another page the order which was selected by user i.e. 3,2,4,1

Please help..

Thanks in Advance

1 Answers1

2

Chosen Order is a plugin for Chosen which aims to provide functions to handle the order of the selection.

https://github.com/tristanjahier/chosen-order

Update:

<script type='text/javascript'>
var results = [];
$("#city").on('change',function(){
    var selected_values = $(this).val();
    var temp_results = results;
    results = [];

    //FOR REMOVED VALUES
    for(i in temp_results){
        if($.inArray(temp_results[i],selected_values)>=0){
            results.push(temp_results[i]);
        }
    }

    //FOR ADDED VALUES
    for(i in selected_values){
        if($.inArray(selected_values[i],temp_results)<=-1){
            results.push(selected_values[i]);
        }
    }               

    console.log(results.join("::"));
    //Save it in hidden input to pass next page
});
</script>
Jimish Gamit
  • 1,014
  • 5
  • 15
  • Hi bro is there any chances i.e this plugin will work with chosen-0.9.8 ? – Siddeshwar Vanga Feb 08 '16 at 09:42
  • Its for Chosen1.0+. You can write your custom code like `var results = []; $("#ELEMENT").on("change", function(e) { });`. Push id when someone selects and remove id on unselect then pass it to another page – Jimish Gamit Feb 08 '16 at 10:02
  • Updated answer with custom one – Jimish Gamit Feb 09 '16 at 05:23
  • Hi bro, I have done it in similar way, But I am facing problem when i am populating select box. It is populating in ascending order only.can't able to populate values as they were stored. – Siddeshwar Vanga Feb 09 '16 at 08:48