title: Ajax return and append HTML data into table row
body: <p>I have problem with ajax return html data.
  Idea is I have dynamic table that user can add or delete table row, in each of table row there is button that will show modals and user can choose Item, but after user add rows and choose item, item goes to first rows not to new row.</p>
  
  <p>Please your help.</p>
  
  <p>this is my HTML:</p>
  
  <pre><code>    &lt;tr id='addr0' class="itemsGroup"&gt;
                      &lt;td&gt;
                      1
                      &lt;/td&gt;
                      &lt;td width="240px"&gt;
                        &lt;div class="input-group" &gt;
                 &lt;input type="text" name="barang_id" class="form-control" value="&lt;?php echo @$rowID-&gt;barang_id != '' ? $rowID-&gt;barang_id : $this-&gt;session-&gt;flashdata('barang_id') ;?&gt;"&gt;
                 &lt;span class="input-group-addon" id="basic-addon1"&gt;
                  &lt;a href="#myModalItems" class="trash" role="button" data-toggle="modal"&gt;&lt;span class="glyphicon glyphicon-list"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;
                        &lt;/div&gt;
                &lt;/td&gt;
                      &lt;td&gt;
                      &lt;input type="text" name="barang_name[]" class="form-control" &gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                      &lt;input type="text" name="barang_satuan[]" class="form-control" &gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                      &lt;input type="text" name="barang_unit_price[]" class="form-control" &gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                      &lt;input type="text" name="barang_qty[]" class="form-control" &gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
  </code></pre>
  
  <p>My Modal :</p>
  
  <pre><code>&lt;div class="modal-header"&gt;      
      &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
      &lt;h4 class="modal-title" id="myModalLabel"&gt;Items&lt;/h4&gt;
     &lt;/div&gt; 
      &lt;div class="modal-body"&gt;&lt;div class="panel panel-default" &gt;
                     &lt;div class="panel-heading"&gt;
                      &lt;table id="mytablex" class="display" &gt; 
                          &lt;thead&gt;
                           &lt;tr &gt;
                            &lt;th width="55px"  style="text-align:center;"&gt;&amp;nbsp;&lt;/th&gt;
                            &lt;th width="55px"  style="text-align:center;"&gt;No.&lt;/th&gt;
                            &lt;th width="240px" style="text-align:center;"&gt;Item No.&lt;/th&gt;
                            &lt;th width="240px" style="text-align:center;"&gt;Item Name&lt;/th&gt;
                           &lt;/tr&gt;
                          &lt;/thead&gt;
                          &lt;tbody&gt;
                            &lt;?php 
                             $counter = 1;
                            if ($resultBarang) {
                             foreach ($resultBarang as $row) {
  
                              if ($counter%2 ==0) { $class = 'list01';}else {$class = 'list02';}    
                               ?&gt;
                            &lt;tr class="&lt;?php echo $class;?&gt;"&gt;
                             &lt;td width="55px" align="center"&gt;&lt;input type="radio" onclick="getItemsID(this.value);" name="supid" id="supid" value="&lt;?php echo $row-&gt;barang_id;?&gt;"&gt;&lt;/td&gt;
                             &lt;td width="55px" align="center"&gt;&lt;?=$counter?&gt;.&lt;/td&gt;
                             &lt;td width="240px" &gt;&lt;?=$row-&gt;barang_no;?&gt;&lt;/td&gt;
                             &lt;td width="240px" &gt;&lt;?=$row-&gt;barang_name;?&gt;&lt;/td&gt;
                             &lt;/tr&gt;
                            &lt;?php $counter++;}} ?&gt;
                          &lt;/tbody&gt;
  
                          &lt;/table&gt;
                           &lt;/div&gt;
                          &lt;/div&gt;
       &lt;/div&gt;   
       &lt;div class="modal-footer"&gt;
               &lt;button class="btn btn-danger" data-dismiss="modal" aria-hidden="true"&gt;Close&lt;/button&gt; 
            &lt;/div&gt; 
  
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;   
  </code></pre>
  
  <p>after select checkbox i'm using this script :</p>
  
  <pre><code> function getItemsID(supid){
          $.ajax({
          type: 'post',
          url: '&lt;?php echo base_url();?&gt;admin/po_trans_po/getItemsId',
          data:'id='+supid,
                    success: function(data){
                        $(".itemsGroup").html(data);
              $('#myModalItems').modal('hide');
          }
        });
      }
  </code></pre>
  
  <p>and then this is my PHP file :</p>
  
  <pre><code>  function getItemsId()
   {
     $id = $this-&gt;input-&gt;post('id');   
     $resultBarang = $this-&gt;db-&gt;query("select * from `st_po_barang`  a,st_po_harga_barang c
                     where c.barang_id = a.barang_id
                     and now() between c.harga_start_date and c.harga_end_date
                     and a.barang_id = $id
                     ");
  
     $resultBarang =  $resultBarang-&gt;row();
      echo '              &lt;td&gt;               ';
      echo '              1                  ';
      echo '              &lt;/td&gt;              ';
      echo '              &lt;td width="240px"&gt; ';
      echo '                &lt;div class="input-group" &gt;';
    echo ' &lt;input type="text" name="barang_id" class="form-control" value="'.$resultBarang-&gt;barang_no.'"&gt; ';
      echo '           &lt;span class="input-group-addon" id="basic-addon1"&gt;                                                                                                           ';
      echo '            &lt;a href="#myModalItems" class="trash" role="button" data-toggle="modal"&gt;&lt;span class="glyphicon glyphicon-list"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;                            ';
      echo '                &lt;/div&gt;                                                                                                                                                        ';
      echo '          &lt;/td&gt;                                                                                                                                                         ';
      echo '              &lt;td&gt;                                                                                                                                                            ';
      echo '              &lt;input type="text" name="barang_name[]" value="'.$resultBarang-&gt;barang_name.'" class="form-control" &gt;                                                                                                  ';
      echo '              &lt;/td&gt;                                                                                                                                                           ';
      echo '              &lt;td&gt;                                                                                                                                                            ';
      echo '              &lt;input type="text" name="barang_satuan[]" value="'.$resultBarang-&gt;barang_satuan.'"class="form-control" &gt;                                                                                                ';
      echo '              &lt;/td&gt;                                                                                                                                                           ';
      echo '              &lt;td&gt;                                                                                                                                                            ';
      echo '              &lt;input type="text" name="barang_unit_price[]" value="'.$resultBarang-&gt;harga_beli.'"class="form-control" &gt;                                                                                            ';
      echo '              &lt;/td&gt;                                                                                                                                                           ';
      echo '              &lt;td&gt;                                                                                                                                                            ';
      echo '              &lt;input type="text" name="barang_qty[]" class="form-control" &gt;                                                                                                   ';
      echo '              &lt;/td&gt;                                                                                                                                                            ';
  
     return 1;
     //redirect('admin/po_trans_po');
   }
  </code></pre>
  
  <p>If i'm adding row table data , this return data keep in first row in table.
  How to return data in selected row?</p>
  
  <p>Regards</p>