Tuesday, 3 December 2013

Jquery:: Decoding JSON array using Jquery


Append  as  <option></option> to <select id="#test"></select> using Jquery from JSON encoded array.

I thought If this help you guys. You can use this to Add <option></option> on the fly using Ajax.

$(document).ready( function() {

var  data = ' [{"orgName":"BHEA Knowledge Technology"},{"orgName":"Microsoft Inc"},{"orgName":"Google Inc"}] ';

var i;
var myData = jQuery.parseJSON(data);
               
 for (i=0; i < myData.length; i ++ )
 {  
      $('#test').append($('<option>', {value: i,text: myData[i].orgName}));                     
 }

});

No comments:

Post a Comment