I wanna ask how to pass the Incremental ID value from table to JQuery using button, the table separate from the main page and I tried using this
$(".btn-success").click(function() {var data = $(this).attr('data-value') console.log(data); });
but only work when I place the code at the table page, not on the main page.
this is my table page:
<?php
include '../tools/koneksi.php';
$sql = "SELECT * FROM menu";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc())
{
echo "<tr>" ;
echo "<td>" . $row["id"] . "</td>" ;
echo "<td>" . $row["Pilihan Menu"] . "</td>" ;
echo '<td> <button type="button" class="btn btn-block btn-success btn-xs" data-value="'.$row["id"].'">Ubah</button>
<button type="button" class="btn btn-block btn-danger btn-xs" data-value="'.$row["id"].'">Hapus</button> </td>';
echo "</tr>";
}
}
$conn->close();
?>
so there is any way to fix this problem or using any method, I tried using onClick function at the buttons before and it works, but I preffer to use JQuery.
Aucun commentaire:
Enregistrer un commentaire