0

I have small code that generated javascript error when I want to display in console $my_var: I want to display $my_var in the console (I will use it later for append it to a div with jQuery) but I get : Uncaught SyntaxError: missing ) after argument list

PHP:

$my_var = '<script id=\'et4pages\'></script>';
echo '<a href="javascript:display_content(\''. $my_var .'\');">click here</a>';

Javascript :

function display_content(link) {
            console.log(link);
    }
3
  • What error is showing ? Commented Sep 6, 2016 at 9:09
  • what exactly you want to do Commented Sep 6, 2016 at 9:11
  • just display the $my_var, I will use it later for jQuery Commented Sep 6, 2016 at 9:15

1 Answer 1

1

please try this , let me know how much it works then tell me what you want in that OR try it by yourself

    <?php 
$my_var = "<script id=\'et4pages\'></script>";
echo '<a href="javascript:display_content(\''. $my_var .'\');">click here</a>';
?>
<script>
function display_content(link) {
            console.log(link);
    }
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

thank you but the problem was not in "click here", I just replaced a language var by simply "clic here " for that example
i have made some changes now it showing in console please check
You should explain what did you change.
i have replaced the ' to " in $my_var

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.