admin管理员组

文章数量:1323211

The below code is in PHP

echo "<input type='submit' name='delete' value='$t2[0]' class='delete_button' onclick='return confirm('Please Confirm Delete');'>"

I am trying to create a delete button, when a user clicks on delete button , it should ask confirmation. but in this case, its not working.

is there any best way to delete with confirmation in php with/ or javascript and no ajax

The below code is in PHP

echo "<input type='submit' name='delete' value='$t2[0]' class='delete_button' onclick='return confirm('Please Confirm Delete');'>"

I am trying to create a delete button, when a user clicks on delete button , it should ask confirmation. but in this case, its not working.

is there any best way to delete with confirmation in php with/ or javascript and no ajax

Share Improve this question edited Nov 23, 2011 at 12:26 Rafee asked Nov 23, 2011 at 12:21 RafeeRafee 4,0788 gold badges61 silver badges89 bronze badges 1
  • 1 onclick='return confirm("Please Confirm Delete");' – Mohit Bumb Commented Nov 23, 2011 at 12:28
Add a ment  | 

5 Answers 5

Reset to default 6

Your quotes are breaking themselves here;

onclick='return confirm('Please Confirm Delete');'>

Instead use;

onclick="return confirm('Please Confirm Delete');">

Well, in javascript you can do it as:

<input type='submit' name='delete' value='$t2[0]' class='delete_button' onclick='return askme();'>

//javascript function
function askme() {
  if(confirm("Are you sure you want to delete this..?")) {
     //delete someting
  }
}

The quotes are going wrong, use this instead:

 echo "<input type='submit' name='delete' value='$t2[0]' class='delete_button' onclick='return confirm(\"Please Confirm Delete\");'>"

You are going out of your attribute by opening the single quote again inside your confirm.

You cannot "call php code into jquery". The only thing you can do is to set up a request (AJAX) to a server side PHP script which will take over the respective parameters you transferred to the script and produce an output (using echo or print) which will automatically be available in the request's callback.

With jQuery it's as easy as that

$.post('url/to/script.php', {parameter1: 'whatever', param2: 'something'}, function(response) {
   // the output of the PHP script is available in the variable "response"
   alert(response);
});

The PHP script can take over the parameters, take any action with it and create output

$param1 = $_POST["parameter1"];
$param2 = $_POST["param2"];
// do whatever you want with $param1 and $param2
// create some output using echo/print
echo "This will be transferred back to the calling Javascript";

You can try this, quite easy and it works.

   <td> <a  onClick="return confirm('DELETE: Are You sure ??');"  href="member_delete?id=<?php echo $row['memID'];?>" >delete <i class="fa fa-trash-o" aria-hidden="true"></i></a></td> [DEMO][1]

I assume, its in a table list of members.

本文标签: php javascript confirm box for deleteStack Overflow