Raymart C. Lopez Raymart C. Lopez - 4 months ago 7
MySQL Question

Confirm dialog doesnt work well

Can somebody help me with my code. whenever i want to delete data from my table a dialog will pop up if i want to delete the item but eventhough i press the cancel button still it delete the item.. here is my code

echo"<td> <center><a href ='delete.php?house_id=$id'><button type='button' onclick='ConfirmDelete()'' class='btn btn-info btn-md'><span class='glyphicon glyphicon-trash'></span>Delete</button></a></center></td>";
echo"</tr>";
$count++;
}
?>
<script type="text/javascript">
function ConfirmDelete(){
if (confirm("Delete Account?"))
location.href='delete.php';
}
</script>

Answer

Try this:

<script type="text/javascript">
function ConfirmDelete(){
    if (confirm("Delete Account?")){
        location.href='delete.php';
    }
    else {
       return false;
    }
    }
</script>

And update onclick='return ConfirmDelete()'

Comments