php - get values in jquery -


i have list of results database choice accept or delete request of inscription :

   foreach ($data $key )      {       ?>        <tr>             <td><?php echo $key['pseudo'];  ?></td>             <td><?php echo $key['email'];  ?></td>             <td>non valider</td>             <td><button class="btn btn-success btn-sm" id="ok"  data-val="<?       php echo $key['id'];?>">valider</button></td>             <td> <button class="btn btn-danger btn-sm" id="non" data-id="<?php echo $key['id'];?>">supprimer</button></td>        </tr>               <?php } ?>    

i want if click in button value of data-val. use code:

  $(function() {         $('#ok').click(function(){           var t=$("#ok").attr("data-val");           alert(t);         })   }); 

but correcte juste first result.

i see you're doing foreach possibly result in multiple buttons same id ok. ids must unique. use class instead.

replace button html below

<button class="btn btn-success btn-sm ok-btn"

and in jquery

$('.ok-btn').click(function(){     var t = $(this).attr("data-val");     alert(t); }); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -