-2

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.'");>';

?>
Charlie
  • 22,886
  • 11
  • 59
  • 90
Stranger
  • 864
  • 4
  • 21
  • 48
  • This is not the duplicate of the link you posted @splash58.. please check carefully. – Stranger Jul 18 '16 at 16:10
  • @IsmailRBOUH, I tried this.. I get same error – Stranger Jul 18 '16 at 16:10
  • That code you provided shouldn't be giving you that error. It would at least generate this html: `
  • ` – FirstOne Jul 18 '16 at 16:10
  • @Philipp, this is the only error message I am getting in my console. – Stranger Jul 18 '16 at 16:11
  • @FirstOne, it does convert it to James Wilson (As per the source screen on my webpage). But the error is still there.. – Stranger Jul 18 '16 at 16:15
  • `echo '
  • ';` - https://eval.in/607228
  • – splash58 Jul 18 '16 at 16:28