javascript - Confirm before delete -


below want confirm before deleting record, problem here whether select ok or cancel confirmation box record gets deleted on both, secondly not getting redirected required page after deletion.

<script type="text/javascript"> function confirmdelete(){ if (confirm("delete account?")){       window.location='mains.php'; } else {    // nothing } } </script>  if(isset($_post['submit'])){ $que=$db->prepare("delete blogs id = :id"); $que->execute(array(':id'=>$postid)); }  <form method="post">   <input type="submit" name="submit" value="delete" onclick="confirmdelete()" /> </form> 

so delete button submit form can change html code of form to

<form action="mains.php" method="post" onsubmit="return confirmdelete()">       <input type="submit" name="submit" value="delete"  /> </form> 

and confirmdelete function to

function confirmdelete(){     if (confirm("delete account?")){           return true;     }     else {        alert('sorry');        return false;     } }   

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -