Jquery getJSON populate select menu question

$.getJSON('selectMenus.php', function(data){
    var html="";
    var len = data.length;
    for (var i = 0; i< len; i++) {
        html += '<option value="' + data[i].monthId + '">' + data[i].month + '</option>';
    }
    $('select.month').append(html);
});

Storing the HTML code in a variable and appending it only once at the end is very important if you care about your app performance.

Leave a Comment