I have this code is about delete rows in table with confirm. everything is correct and work but in confirm when I click cancel not working it delete row
I want to konw wate is the problem when clicking cancel
here is my code

<script type="text/javascript">

function show_confirm()
{
var r=confirm("Are you sure you want to drop this appointment?!");
if (r==true)
  {
  alert("The appointment has been canceled!");
  }
else
  {
  alert("Cancel!");

  }
}


<a href=viewp.php?appc=$appcode onclick='show_confirm()' value='drop'>Drop</a>
if (r==true){
//here will be th query for delete  
}

Try this...create a test page by copying the codes below and save it as delete.php

 <script type="text/javascript">
function check(){
var r = confirm("Are you sure you want to drop this appointment?!");
if(r){

return true;

}
else{

alert("The appointment will not be cancelled");
return false;

}

}
</script>
<a href="delete.php?delete=yes" onclick="return check();" />Delete</a><br/>
<?php

if(isset($_GET['delete'])){

 ## this is where you put the deletion, but make sure to get the right info.
 echo "Appointment has been cancelled";
}

?>

Codes above should mimic the process with alert and confirmation ..Then should echo Appointment has been cancelled, if choose to drop appointment. I hope you are seeing the pattern here when javascript is used along side with php. Php will not wait for this "alert("The appointment has been canceled!");".. Unless, you make a switch or if statement to confirm that the delete value has been passed.

However, the javascript will be responsible for allowing the href to get through and therefore, setting off the isset to true. Observe closely, when the prompt is on, the url of the page is at default, but when you confirm the delete, the url goes to delete.php?delete=yes, and that is the triggering mechanism for the php script. Making this if(isset($_GET['delete'])) equal to true.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.