I am trying to pass a php variable inside js function but I am getting the following error:
Uncaught SyntaxError: Invalid or unexpected token
Here's my code:
<?php
$author ="James Wilson";
echo '<li onClick= getAuthor("'.$author.'");>';
?>
I am trying to pass a php variable inside js function but I am getting the following error:
Uncaught SyntaxError: Invalid or unexpected token
Here's my code:
<?php
$author ="James Wilson";
echo '<li onClick= getAuthor("'.$author.'");>';
?>
echo "<li onclick=\"getAuthor('$author')\">";
You know that you need to pass a string to onClick
attribute. In plain html it should be:
<li onClick="getAuthor('someone')">
Construct this with proper escape characters in php.
echo '<li onClick= "getAuthor(\'' . $author . '\')";>';