I have PHP code that tries to output JavaScript and I do something like this:
trailhead_name = <?php echo $objkey->trailhead_name ?> + "";
And I get the unexpected identifier error in my JS.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If
trailhead_nameis a string, you need to put quotes around it (and properly escape anything within it that may not be a valid JavaScript string — like a quote!).PHP’s built-in JSON encoder can do that for you:
Again, that assumes that
trailhead_nameis a string.