How to confirm row deletion

1

I would like to ask whether or not they want to eliminate a Patient by means of a YES or NOT something simple ... I've tried and he asks me if he wants to delete it using Javascript, but he does not do anything ...

<a href='pagines/esborrar.asp?id=<%=rs("Numero")%>&que=<%=nomfitxer%>'><img src="images/delete.gif" border="0" alt="Borrar" /></a>

This is what I've tried:

Script

function irAWeb() {

  if (confirm("¿Quieres ir a la página del Mensajeitor?")) {

    document.location.href = 'pagines/esborrar.asp?id=<%=rs("Numero")%>&que=<%=nomfitxer%>';
  }
}
<a onclick="irAWeb(); return false;" href='pagines/esborrar.asp?id=<%=rs("Numero")%>&que=<%=nomfitxer%>'><img src="images/delete.gif" border="0" alt="Borrar" /></a>
    
asked by sergibarca 24.08.2017 в 14:27
source

1 answer

4

The problem is that you are canceling the event yes or yes with that return false .

Also, if the href indicates the destination you do not need the document.location.href .

Delegating the value of return to the call will work as you wish:

function irAWeb(event) {
  if (confirm("¿Quieres ir a la página del Mensajeitor?") == false) {
    event.stopPropagation();
    event.preventDefault();
    return false;
  }
  return true;
}
<a onclick="return irAWeb(event);" href='pagines/esborrar.asp?id=<%=rs("Numero")%>&que=<%=nomfitxer%>'> [Pulse para borrar] </a>

After giving more details in the chat I made one last modification to cancel the propagation of events with Event.stopPropagation() to prevent the parent element (a <tr> with another event onclick ) from doing an action when canceling the deletion.

It is important to pass the event as a parameter to the function with onclick="return irAWeb(event);" .

    
answered by 24.08.2017 / 14:39
source