Stackoverflow response: jquery json to select issues

http://stackoverflow.com/questions/16150540/jquery-json-to-select-issues/16150774#16150774

by Terry Young

HTML

<select id="country"></select>

JavaScript

var data = {"DATA":[{"COUNTRYCODE":"1","DESCRIPTION":"USA","COUNTRYID":"211"},{"COUNTRYCODE":"1","DESCRIPTION":"Canada","COUNTRYID":"37"},{"COUNTRYCODE":"1","DESCRIPTION":"Dominican Republic","COUNTRYID":"224"}]};
                       
    var $select = $('#country')
        .empty()
        .on('change', function () { 
            console.info($(this).find('option:selected').data('DATA')); 
        });
    
    $select.append(
        data.DATA.map(function (el, i) {
            return $('<option>')
                .val(el.COUNTRYID)
                .text(el.DESCRIPTION)
                .data('DATA', el); // just in case you also want to access COUNTRYCODE
        })
    );