Javascript alert box - display single quotes or apostrophe

I have a problem with displaying of single quote character or apostrophe in javascript alert box. I am using combination of single and double quotes in related PHP / HTML. What should I do to be sure that single quotes will appear in alert box notification ?
give a positive ratinggive a negative rating
03 Feb 2021 at 06:09 PM

The situation when using mulitple combinations of single and double quotes in PHP is quite common. To show javascript Alert notification with single quote, you will need to use escaped quotes and addslashes() function in your solution.

This combination of regular and escaped single and double quotes should work:

$notification = "'Content in single quotes'";

echo "<a href=\"javascript: void(0);\" onClick=\"javascript: alert('".addslashes($notification)."');\" >Show notification</a>";

give a positive ratinggive a negative rating
14 Feb 2021 at 04:35 PM
Share on FacebookShare on TwitterShare on LinkedInSend email
2023 AnswerTabsTermsContact us
How would you rate your experience with AnswerTabs ?
Very badVery good
Thank you for your feedback.