Reputation: 3
index.html
<?php
while($admin_data=mysql_fetch_row($query2)){
?>
<tr>
<td><?php echo $admin_data[0];?></td>
<td><?php echo $admin_data[1];?></td>
<td><?php echo $admin_data[2];?></td>
<td><?php echo $admin_data[3];?></td>
<td><a href="javascript:void()" id="delete">Delete</a></td>
</tr>
<div id="result_delete"></div>
<?php
}
?>
jquery file
<script>
$(document).ready(function(){
$("#delete").click(function(){
$("#result_delete").load("delete.php");
});
});
</script>
delete.php
<?php
include "db/db.php";
if($_GET['drop']){
$drop=$_GET['drop'];
}
echo $drop;
?>
how to pass value to delete.php page. i want to pass a variable to url thanks for your answers
Upvotes: 0
Views: 712
Reputation: 207501
IDS are SINGULAR they can not repeat. Use a class.
<td><a href="javascript:void()" class="delete">Delete</a></td>
and
$(".delete").click(function(){
better yet
$("#tableId").on("click", ".delete", function(){
And hopefully the <div id="result_delete"></div>
does not live right after the TR since that is invalid HTML markup.
Since you can not figure out how to get the id, it is simple.
$("#tableId").on("#click", ".delete")function(){
var val = encodeURIComponent($(this).data("val"));
$("#result_delete").load("delete.php?drop=" + val);
});
Doing a delete request with a get request is a bad idea
Upvotes: 4