the server returns following response query:
{ rom: "romania", yug: "yugoslavia", prt: "portugal", mkd: "macedonia", grc: "greece", fra: "france", isl: "iceland", lux: "luxembourg", hun: "hungary", gbr: "united kingdom", 36 more… }
i need put these existing select so:
$.each(result, function(key, value) { $('#country') .append($("<option></option>") .attr("value",key) .text(value)); });
can tell me how sort countries alphabetically value before inserting them html element?
function orderlistby(prop) { return function (a, b) { if (a[prop] > b[prop]) { return 1; } else if (a[prop] < b[prop]) { return -1; } return 0; } }
call function: sort name -
yourarray.sort( orderlistby("name") );