Onclick-> return confirm('..') doesn't work. why?

Hello,
I used to use below code to make it confirm.

echo "<td<a href=\\"makeAvailable.php?id=$id\\" onclick=\\"return confirm('Are you sure you want to share{$title}?');\\">Share this item</a></td>";

It worked fine until $title was “What’s so amazing?”
As you see, $title has ’ in that, so no confirm box is shown, just go to the makeAvailable.php right away.
Is there anyway I can solve this problem?

Thanks

hmm… try this… i typically use single quotes for html so i dont have to escape all attribute values…


echo '<td><a href="makeAvailable.php?id='.$id.'" onclick="return confirm(\\'Are you sure you want to share '.$title.'?\\')">Share this item</a></td>';

No it doesn’t work

Try

echo '<td><a href="makeAvailable.php?id='.$id.'" onclick="return confirm(\\'Are you sure you want to share '. addslashes($title) .'?\\')">Share this item</a></td>'; 

Join the dark side, use print with double quotes…

print ("<td><a href=\\"makeAvailable.php?id=$id\\" onclick='return confirm(\\"Are you sure you want to share $title?\\",alert(\\"eek a mouse!\\"))'>Squash this item</a></td>");

alright well i have no idea what your problem is then… i tried this and it works fine…



<html>
<body>

<?php
$id=1;
$title = "What's happening";
echo '<a href="makeAvailable.php?id='.$id.'" onclick="return confirm(\\'Are you sure you want to share '. addslashes($title) .'?\\')">Share this item</a>';
?>
</body>
</html>

that works fine… all i changed was i took out your <td></td> tags. also note in your original post you were missing a closing > on the first td…

Edit:

and i added addslashes.