0

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

3
  • Your HTML will have multiple elements, all with an id of delete. Commented Dec 19, 2013 at 17:09
  • thanks for comment.i got the solution by changing id to class. Commented Dec 19, 2013 at 17:22
  • i also want to know .that how to send variable of particular anchor Commented Dec 19, 2013 at 17:22

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

9 Comments

its working fine..so nice of you ..thanks alot :) :)
i also want to know .that how to send variable of particular anchor
What variable... Use a data attribute <a href="javascript:void()" data-val="1234" ../> and use $(this).data("val")
where to add $(this).data("val")
It is best practice here not to keep updating questions with more requirements. Make new questions. What do you not understand, get the value inside the onclick, use it. function() { var myVal = $(this).data("val"); alert(myVal); }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.