title: Display the value from database to dynamically created textfield in the table using jQuery
body: <p>I going to display the value from the database to the dynamically created textfields to each table cell using JQuery. (Note that the fetch values Im going to display are not all same.) The 'lvl' (e.g. lvl1 or lvl2) are the values from database, not an id or class of textfields.</p>
  
  <p>Here's what it looks like..</p>
  
  <pre><code>      | itm1 | itm2 | itm3 | itm4 | itm5
  ------|------|------|------|------|-----
  skill1| lvl2 | lvl3 | lvl1 | lvl4 | lvl0
  ------|------|------|------|------|-----
  skill2| lvl1 | lvl0 | lvl4 | lvl2 | lvl1
  ------|------|------|------|------|-----
  skill3| lvl4 | lvl2 | lvl3 | lvl0 | lvl1
  </code></pre>
  
  <p>My JQuery,</p>
  
  <pre><code>$('tbody tr td').click(function(){
    var row = $(this).closest('td');
    var skill = row.find('.skillID').val();
    var item = row.parent().children().index(row);
  
    $.ajax({
      type: "POST",
      url: "&lt;?php echo base_url(); ?&gt;controller/get_level",
      data: {'Skill_ID':skill,'Item_ID':item},
      cache: false,
      success: function(data){
         alert("Level "+data);
       }
    });
  });
  </code></pre>
  
  <p>The above code was successful in alert and click func, but I need to display the data in textfield by clicking the "td" or when the page was loaded, the value would display automatically.</p>
  
  <p>view,</p>
  
  <pre><code>&lt;thead&gt;
    &lt;tr&gt;
       &lt;td&gt;&amp;nbsp;&lt;/td&gt;
       &lt;?php foreach($items as $item): ?&gt;
         &lt;td&gt;&lt;?php echo $item-&gt;ItemID ?&gt;&lt;/td&gt;
       &lt;?php endforeach; ?&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;?php foreach($skills as $skill): ?&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;?php for($i=0; $i&lt;count($items); $i ++){ ?&gt;
         &lt;td&gt;&lt;input type="text" value="" /&gt;
         &lt;input type="hidden" class="skillID" value="&lt;?php echo $skill-&gt;Skill_ID" ?&gt; /&gt;
         &lt;/td&gt;
      &lt;?php } ?&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>