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.
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.
If trailhead_name is 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:
trailhead_name = <?php echo json_encode($objkey->trailhead_name) ?>;
Again, that assumes that trailhead_name is a string.