Tip: Click lines to highlight, hold ctrl/cmd to multi-select

Build Options html from json response (18-Jan @ 14:35)

brentg

Syntax Highlighted Code

  1. //return JSON Object
  2. $.getJSON(selectedInstrumentAjaxCallUrl, {instrument:ticker}, function(json) {    
  3.     //build options html
  4.     var optionsHtml = '';
  5.     for (var i = 0; i < json.length; i++) {
  6.             optionsHtml += '<option value="' + json[i].optionValue + '">' + json[i].optionDisplay + '</option>';
  7.     }
  8.    
  9.     $("#select1").html(optionsHtml);
  10.     $("span.ajax-load").remove();
  11.     $("#select1").removeAttr("disabled");
  12.     $('#select1 option:first').attr('selected', 'selected');
  13.     })
  14. })
  15.  

Plain Code

//return JSON Object
$.getJSON(selectedInstrumentAjaxCallUrl, {instrument:ticker}, function(json) {    
    //build options html
    var optionsHtml = '';
    for (var i = 0; i < json.length; i++) {
            optionsHtml += '<option value="' + json[i].optionValue + '">' + json[i].optionDisplay + '</option>';
    }
    
    $("#select1").html(optionsHtml);
    $("span.ajax-load").remove();
    $("#select1").removeAttr("disabled");
    $('#select1 option:first').attr('selected', 'selected');
    })
})

Codedump Run

Permalink: http://codedumper.com/build-options-html-from-json-response