Message asking if I am sure of this action in html and php

0

I have been investigating in this forum and in others for some time, and I can not find out how in the present list I am working with, I can delete the record, but first ask if I am sure. I'm doing it this way:

echo "<script>
    function Borrar()
    {
       confirm('Estas Seguro que deseas Borrar este Registro?');
    }
</script>";

Then where do I call the function:

echo "<td align='center' class='borrar'><a onclick='Borrar()' href='borrar_estudiante.php?id=$estudiante[cedula]'><img src='../imagen/delete.png'></a></td>";

The message appears fine, but if I give cancel it goes to the next page, having deleted that record. In other words, if I accept or cancel, it will do the same.

I've tried other functions and if this does not happen, then it does not even look like the message.

It's something simple to do, but I hope you can help me.

    
asked by Carlos Agustin Guanipa Alvarez 26.02.2018 в 02:43
source

1 answer

1

It should be something like:

echo "<script>
function Borrar()
{
   if(confirm('Estas Seguro que deseas Borrar este Registro?')){
    return true;
   }
   else{
    return false;
   }
}
</script>";

This is why the confirm returns true when you accept or false when you cancel

EDIT: The link should be as follows

echo "<td align='center' class='borrar'><a onclick='return Borrar();' href='borrar_estudiante.php?id=$estudiante[cedula]'><img src='../imagen/delete.png'></a></td>";

Here's the example: link

    
answered by 26.02.2018 / 04:09
source