I have the following code to sort the items in a dropdown list:
function sortDropDownListByText(selectId) {
$(selectId).html($(selectId + \" option\").so
First you have to preserve the selected value, and once you finished the sorting you re-select the preserved value.
#store the selected value.
var selectedVal = $(selectId).val();
# start sorting.
$(selectId).html( $(selectId+" option").sort(function(a, b) {
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
}));
#re-select the preserved value.
$(selectId).val(selectedVal);