and later this:
“<input…onclick='test(\”“.$text.”\“);'>”
and test() is:
function test(a){alert(a);}
The function doesn’t display anything with “test’it” but displays “test it” ok. Htmlentities doesn’t fix it and I can’t find any other solution.
Thanks
First question: Did you put <input… inside the <php?..brace? That is the only way you can add $text to the js mothod. Unless I am wrong. Someone chime in…
Yes. More fully it’s:
<?php
$text=“test’it”;
…
echo “<input…onclick='(\”“.$text.”\“);'>”;
?>
I tried addslashes($text) as well as htmlentities but still no good.
' is the HTML code for the apostrophe. Remember, you’re concatenating two strings through PHP which then get “unstringed”. Lol it’s confusing but here’s a visualization of what’s happening:
<input...onclick=' (\\ " test' it ' " );'>
_________________------------____-------__
Underscores are regular characters and hyphens are strings.