There are many questions about escaping single and double quotes but I have had no luck finding an answer that solves my particular problem.
I have a PHP function that dynamically returns an image with an onClick event that calls a Javascript function with the name of an object as an argument like so:
$response = <img src=images/action_delete.gif onClick=confirmDelete(' . $event->getName() . ')/>;
The Javascript function should display a confirmation dialogue at some point like this:
confirm('Delete event ' + name + ' ?')
How should I format $response in PHP to make sure the Javascript confirm won't mess up when the user enters a name containing ' or or ' or ?