Get the data that is being loaded by jquery in PHP CodeIgniter -


i have dropdown menu using form_helper in codeigniter:

  <?php if($materialtype): ?>      <?php      $material_options = array();     foreach($materialtype $rows){         $material_options[$rows->id] = $rows->category;      }                                            echo form_dropdown('materialtype',$material_options,'','id="materialtype"');     ?>  <?php endif; ?>    <div id="materials"></div> 

the code above inside <form> tag , have script:

  <script type="text/javascript">     var base_url = "<?php echo base_url(); ?>";    </script>    <script>      $(document).ready(function(){         $(document).on('change','#materialtype',function(){                 loadthis();                              });              function loadthis(){                 var id  = $('#materialtype').val();                  var datastring = 'id='+ id ;             $.ajax({                 type: "post",                 url: base_url + "index.php/admin/get_material",                 data: datastring,                 cache: false,                 success: function(data)                     {                     $('#materials').html(data);                     }                 });                  }              loadthis();         });   </script> 

and here code being loaded:

   <div id="materials">    <?php if($materials): ?>         <table>              <th>name</th>             <th>description</th>             <?php foreach($materials $row): ?>             <tr>                 <td><?php echo $row->mname; ?></td>                 <td><?php echo $row->mdesc; ?></td>                  <td>                     <button class="try" value="<?php echo $row->id; ?>">add</button>                 </td>              </tr>      <?php endforeach; ?>      </table>  <?php else: ?>     <div class="alert alert-error" style="width:300px;">no resource available!</div> <?php endif; ?> 

   $(document).on('click','.try',function(){             alert($(this).val());             return false;         }); 

and want if add button being click can id,mname , store until form submitted.
how can using .data() in jquery? or ideas on how store until form being submit.

i didn't thoroughly @ code, noticed when print table rows in loop have id="try" assigned of rows. html id-attribute unique identifier js alerting value return value of first id find (at least that's think). try use class instread of id , use this in js.

$(document).on('click','.try',function(){     alert($(this).val());     return false; }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -