PHP does not run Onclick Return confirm

Asked

Viewed 690 times

-1

I’m having trouble running javascript inside PHP "echo", I’ve made some changes and the problem persists.

Follow the code I’m using:

 echo "<a href='excluir.php?id_edital=" . $pegar['id_edital'] . "; onClick='return confirm('Deseja realmente deletar o edital?')''><button id='submitdel'><img id='icon-trash' src='images/trash.png'> Excluir</button></a>";
  • 1

    href is not being closed! Oce opens the single quote but does not close it.

  • There’s no missing one ' ending the value of href? Just look at the generated HTML and check the syntax.

  • and onClick='return confirm(' is incorrect, it is necessary to use scape: onClick='return confirm(\"..\"'

1 answer

3


In the part where you are onClick, see that right after the word confirm you have another ' (single quote), as it was used as the onClick action opening, you are closing it there. Place a (") double quote with a bar before.

Would look this way:

echo "<a href='excluir.php?id_edital=" . $pegar['id_edital'] . "' onClick='return confirm(\"Deseja realmente deletar o edital?\")'><button id='submitdel'><img id='icon-trash' src='images/trash.png'> Excluir</button></a>";

Making this correction, I believe it now works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.