Dont ask me why it is the way it is since it is not my code. This is the snippet from the code:
JS:
var myTitle = "<?= $this->myTitle ?>";
Now this works perfect but if $this->myTitle contains a double quote in it it breaks the Javascript code. Is it possible to escape this on JS side and still display the double quote?
The JS error message that I get:
SyntaxError: missing ; before statement
var myTitle = ""A" Test Title";
Things I want to avoid doing:
- I do not want to change
"<?= $this->myTitle ?>"to'<?= $this->myTitle ?>'because it might contain single quote as well. - I can not modify the code where I assign
$this->myTitleto a hidden input and then grab it using JS. (Not up to me) - Can not instal any plugins nor can I download any libraries to do so
- Can NOT modify PHP code to add slashes or encode it using JSON
Is there a simpler solution that only requires Javascript code modification?