I have web application in which i populate listbox using items from database on page load.
I get the all items from listbox that are selected but they are in order in which they populated.
I want these items to be in the order that they are selected by user.
I tried .change(function() using jQuery but it returns only first selected items value.
I attaching my code for reference. I have used listbox using http://harvesthq.github.com/chosen/
This is my listbox:
<asp:ListBox ID="dr_menuitem" runat="server" class="chzn-select" SelectionMode="Multiple" style="width:300px;" >
<asp:ListItem></asp:ListItem>
</asp:Listbox>
This is the jQuery I call:
<script type="text/javascript">
$(document).ready(function() {
$('#dr_menuitem').change(function() {
alert($("#dr_menuitem option:selected").val());
});
});
</script>
To get the selected value in selected order try this:
$("#dr_menuitem").change(function() {
// $(this).val() will give you an array
// of selected value in order
// you've selected
alert( $(this).val() );
});
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With