php javascript confirm box for delete


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




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 yourconfirm.




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"

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.

People are also looking for solutions to the problem: php - Serve static files from another server while keeping the process invisible


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.