0

I have a link inside PHP Echo function called "Delete". When user clicks on it, the delete.php page is called and the selected book is deleted from the database. So, I would like to insert a confirmation box asking user if he is sure to delete the book but I don't know how to do it.

This is the code:

echo "<td><a class = 'echo_link' href='delete-book.php?ID={$Book->ID}'> Delete </a></td> \n";
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
user3156271
  • 39
  • 1
  • 1
  • 2

6 Answers6

5

Use this code:

echo "<td>
<a class = 'echo_link' href='#' onclick='if(confirm(\"message\")) location.href=\"delete-book.php?ID={$Book->ID}\";'> Delete </a>
</td> \n";
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
3

it works perfectly....

 <a  href='http://www.google.com' onclick="return confirm('Are U sure?');"> Delete </a>
Vivek S
  • 2,010
  • 1
  • 13
  • 15
2

Please try this:

echo "<td><a class = 'echo_link' href='delete-book.php?ID=5' onclick='return confirm(\"Are you sure to delete?\")'> Delete </a></td> \n";
2

you can try this code

<?php $bookid =  $Book->ID; ?>
<td>
<a class = 'echo_link' href='<?php echo "delete-book.php?ID=$bookid"; ?>'  onclick='return confirm("Are you sure?");'> Delete </a>
</td> 
<?php echo"\n";
?>
Anil Meena
  • 903
  • 1
  • 12
  • 28
0

Please try this way. It's may helps you.

onclick="return confirm('Are you sure?');"

You can take a look at this demo : http://jsfiddle.net/dq6W6/

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
Lee
  • 10,496
  • 4
  • 37
  • 45
-1

Try this

echo "<td><a class = 'echo_link' onclick='return confirm('Are you sure?');' href='delete-book.php?ID={$Book->ID}'> Delete </a></td> \n";
parker
  • 39
  • 7