title: JQUERY - JSON Result assign it to pre populate form fields on when select is selected
body: <p>I have this requirement form business to Save Searches, allowing users to use saved search data and rerun the search. I have saved the search in database as JSON object. Problem is when users select already saved search via using Select - Dropdown, the form should pre populates all the selections that were saved with search.  When I am trying to alert the key value within populate function - it always show key as 0 and value as whole JSON object. What am I missing here ? </p>
  
  <p>Sample of returned JSON request from database looks like:  {"affects":["153","503","537"],"suspect":["101","108"],"state":[],"zip_code":[],"analysis_date_max":["",""],"last_modified_date_min":["",""]}</p>
  
  <p>Here is my existing code:
  //START OF PROBLEM CODE</p>
  
  <pre><code>function populate(frm, data) {
          var obj  = $.parseJSON(data);
          //alert (data);
          //alert (frm);
  
          alert (obj);
          $.each(obj, function(key, value){
              alert(key + ' is ' + value);
          $('[name='+key+']', frm).val(value);
  
        });
  }
  
  // END OF PROBLEM CODE
      $('#search_dataselect').on('change', function()
      {
         getSearchData(this.value);
  
      });
  
      function getSearchData(search_id) {
  
      if (!isNaN(parseInt(search_id))) {
  
          $.ajax({
              type: "GET",
              url: "/index.cgi?p=json&amp;t=SavedSearch&amp;search_id="+search_id, 
              success: function(result){
              var data  = result;
              populate('#formSearch',data);
  
              },
          });
      }
              return false;
      }
  </code></pre>