Home Ask Login Register

Developers Planet

Your answer is one click away!

Siddeshwar Vanga February 2016

Jquery chosen plugin to post the values, On the order which user selected the data in multiple box

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

Answers


Jimish Gamit February 2016

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>

Post Status

Asked in February 2016
Viewed 1,218 times
Voted 13
Answered 1 times

Search




Leave an answer


Quote of the day: live life