Trying to populate a drowpdown box based on a json object. So data
holds items returned from a table, where item_number
. The below function works, but if there are duplicate item_number
entries, so the options end up like this: 1,2,3,3,3. How do I group the 3
item_numbers ?
//populate #number dropdown
function numbers(data,n) {
$("#number option:not(:first)").remove();
var options = $("#number");
$.each(data, function() {
if(this.item_number != 0)
{
options.append($("<option />").val(this.item_number).text(this.item_number));
}
});
var dropVal = (n != "" ? n : "Issue nr.");
$("#number").val( dropVal );
}
And for bonus points ... how do I order them in ASC
order? At the moment, they are mixed up. Can jquery order them?