I wrote the following code to populate a listbox in Jquery (based on What is the best way to add options to a select from an array with jQuery?)
function populate(id, selectValues, theSelected, empty) {
if (empty) {
$(id).empty();
}
$.each(selectValues, function(key, value) {
$(id).append($("<option></option>").attr("value", key)
.prop('selected', key == theSelected).text(value));
});
}
I call the function using e.g. the following code
populate('#BASE1', {
"8": "2012 average=100",
"7": "2010 average=100",
"6": "2008 average=100",
"5": "2006 average=100",
"4": "2002 average=100",
"3": "2000 average=100",
"2": "1998 average=100",
"1": "1993 average=100"
}, selectedBase, true);
However the list is ordered in the order of the ID - i.e.
How can I adapt my populate function to order them in the order in which I list them? (Obviously I could re-assign the ID's but I was wondering if there is another solution)