I am receiving some code through AJAX and handling it like so:
$verifiedSubject = addslashes(htmlentities($_REQUEST['subject']));
$verifiedBody = addslashes(htmlentities($_REQUEST['body']));
$verifiedAttachment1 = addslashes(htmlentities($_REQUEST['attachment1']));
$verifiedAttachment2 = addslashes(htmlentities($_REQUEST['attachment2']));
echo '<div id="subject" style="text-decoration: underline; cursor:pointer; display: inline; margin-bottom: 2%;" onclick=\'readmore("'.json_encode($verifiedSubject).'", "'.json_encode($verifiedBody).'", "'.json_encode($verifiedAttachment1).'", "'.json_encode($verifiedAttachment2).'")\'>';
echo $_REQUEST['subject'];
echo '</div>';
In the above code I am attempting to convert any HTML code to entities, add slashes to escape single and double quotes, and then json_encode() it for JavaScript to handle in an onclick function.
However, when the text is clicked to inititate the onclick I get this error:
Uncaught SyntaxError: missing ) after argument list
I've tried a variety of PHP functions to try and properly escape this string but nothing seems to work. Can anybody help me out?
Update of page source:
<script>
var date = "Monday, November 16th, 2015 Announcements";
formatAnnouncement( '55',
'Hi',
'<b rgb(0, 0, 0); font-family: Arial, Helvetica, sans; font-size: 11px; line-height: 14px; text-align: justify;\">Lorem Ipsum</b><span rgb(0, 0, 0); font-family: Arial, Helvetica, sans; font-size: 11px; line-height: 14px; text-align: justify;\"> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>',
'0',
'',
'',
'******',
'2015-11-16 16:53:23',
date
);
</script>