d00rman
d00rman

Reputation: 330

Javascript "onclick" doesn't work embed with html & php

I have this delete link with a javascript who will promt Yes or No. But i got nothing promted. I can guess it´s the escaping from php etc. who puts stop in my code? The "onclick" uses "'". and the message uses "'". Is that the problem? And how do i solve it?

PHP/JS

echo "<td><a href='time.php?id=".$row['id']."' onclick='return confirm('Are you sure to delete this ?');'><span class='glyphicon glyphicon-remove text-danger'></span></a></td>";

Upvotes: 0

Views: 201

Answers (3)

I&#39;m Geeker
I&#39;m Geeker

Reputation: 4637

Try this You forget to use \ in your code

echo "<td><a href='time.php?id=".$row['id']."' onclick='return confirm(\"Are you sure to delete this ?\");'><span class='glyphicon glyphicon-remove text-danger'></span></a></td>";

Upvotes: 1

Anand Solanki
Anand Solanki

Reputation: 3425

You have problem with quotes. Pass it properly will resolved the problem.

Do like this:

echo "<td><a href='time.php?id=".$row['id']."' onclick='return confirm(\"Are you sure to delete this ?\");'><span class='glyphicon glyphicon-remove text-danger'></span></a></td>";

Let me know for further query.

Upvotes: 1

blex
blex

Reputation: 25634

You did not escape the quotes around "Are you sure...". Escape them using a \:

echo "<td><a href='time.php?id=".$row['id']."' onclick='return confirm(\"Are you sure to delete this ?\");'><span class='glyphicon glyphicon-remove text-danger'></span></a></td>";

This will output the following HTML:

<td><a href='time.php?id=XX' onclick='return confirm("Are you sure to delete this ?");'><span class='glyphicon glyphicon-remove text-danger'></span></a></td>

Upvotes: 2

Related Questions