Delete record with javascript function

0

Good, what happens is that I have a table, where I have this link to delete a record by php.

<a href="sqlEliminarAlumno.php?txtid='.$rut_alumno.'" onclick="confirmDel()">Eliminar</a>

and I'm trying to delete the record by calling this function,

    function confirmDel()
    {
      var agree=confirm("¿Realmente desea eliminarlo? ");
      if (agree) return true ;
      return false;
    }

but it shows the confirm on the screen, I press cancel and the record is deleted anyway. What is the problem? thanks in advance:)

    
asked by alexi gallegos 04.12.2017 в 18:14
source

1 answer

0

The only thing you need is to return the value of the function when you execute it: onclick="return confirmDel()" to be able to cancel the default operation of the <a>

tag

function confirmDel(){
  var agree=confirm("¿Realmente desea eliminarlo? ");
  if (agree) return true ;
  return false;
}
<a href="sqlEliminarAlumno.php?txtid='.$rut_alumno.'" onclick="return confirmDel()">Eliminar</a>
    
answered by 04.12.2017 / 18:21
source