Pregunta

I tiene esta función js que comprueba si se presiona OK o Cancel y vuelve falsa o verdadera. Lo que estoy tratando de hacer es que cuando es fiel a ejecutar la función js que queda en el orden en que aparecen, pero no está funcionando; deleteList('$row->listID');updateList(); no se ejecutan.

Javascript:

function deleteConfirm(){
    if (confirm("Are you sure you wanna delete that list?")){
            return true;
    }
    else{
            return false;
    }

}

HTML:

<a href="#" id="listID" onclick="return deleteConfirm();deleteList('$row->listID');updateList();">

¿Qué estoy haciendo mal?

Gracias de antemano.

¿Fue útil?

Solución

It's because you're returning on the first statement (so the others never run), instead only hop out on a cancel, like this:

onclick="if(deleteConfirm()) { deleteList('$row->listID'); updateList(); }"

You can also greatly simplify your function, like this:

function deleteConfirm(){
  return confirm("Are you sure you wanna delete that list?");
}

...or if possible go the unobtrusive route, using data- attributes to get the listID.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top