Failed to confirm () in JavaScript [duplicate]

1

I have a functionality so that when you want to delete a Patient by clicking on delete, ask if you really want to delete it or not.

It shows the question, but when I give it to cancel it erases it to me equally and if I give it to accept it happens the same.

The onClick to call the JavaScript function is within a <tr> , that <tr> main also has a onClick , I do not know if that can cause any conflict.

This is the code used:

JS:

function irAWeb(event) {
  if (confirm("¿Quieres ir a la página del Mensajeitor?") == false) {
    event.stopPropagation();
    event.preventDefault();
    return false;
  }
  return true;
}

HTML:

<a onclick="return irAWeb();" 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 в 21:50
source

2 answers

3

The problem must be that you forgot to pass event when calling the function irAWeb in onclick .

Solution:

Modify the HTML in the following way:

<a onclick="return irAWeb(event);" href='pagines/esborrar.asp?id=<%=rs("Numero")%>&que=<%=nomfitxer%>'>
  <img src="images/delete.gif" border="0" alt="Borrar" />
</a>
    
answered by 24.08.2017 / 22:49
source
2

I would not know how to tell you why that happens, I'll always pass by and I'll solve it by adding a more code line, where I get the result of confirm

function irAWeb(event) {
  $bool=confirm("¿Quieres ir a la página del Mensajeitor?");
  if($bool){
  alert("marcaste OK");
  }else{
  alert("marcaste Cancelar");
  }
  
}
<a onclick="return irAWeb();" href='#'> <img src="images/delete.gif" border="0" alt="Borrar" /> </a>

I know that it does not seem to have any change since it would have to be the same, but in this way it works correctly.

    
answered by 24.08.2017 в 22:41