I'm using PHP to generate a Javascript button that adds in a checkbox and some other HTML.
What is the proper way to escape these characters to include them in an onclick event?
I saw it suggested to convert ' and " to the ascii values, but that doesn't seem to have helped.
$tempOutput = "<a href='temp.txt'>\"Happy\"</a>";
$tempOutput = str_replace("'", "'", $tempOutput);
$tempOutput = str_replace('"', """, $tempOutput);
just results in this if you echo the string right before use:
<a href='temp.txt'>"Happy"</a>
and this if you inspect the page element:
<a onclick="
var divTag = document.createElement('div');
divTag.innerHTML = '<a href='temp.txt'>"Happy"</a>';
document.getElementById('extraDiv').appendChild(divTag) ;
">test</a>
I've also tried just appending to the extradiv's innerHTML but no success there either.