I use PHP to create a Javascript button that adds a checkbox and other HTML code.
What is the proper way to escape these characters in order to include them in the onclick event?
I saw that he suggested converting 'and' to ascii values, but that didn't seem to help.
$tempOutput = "<a href='temp.txt'>\"Happy\"</a>";
$tempOutput = str_replace("'", "'", $tempOutput);
$tempOutput = str_replace('"', """, $tempOutput);
just leads to this if you echo the string right before use:
<a href='temp.txt'>"Happy"</a>
and this if you check 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 also tried just adding innerHTML to extradiv, but could not succeed.
source
share