You're missing quotes around your php data, so you're generating invalid javascript. Remember... whatever PHP is outputting has to be correct in a javascript context.
<?php
$foo = 'bar';
?>
<script>
baz = <?php echo $foo ?>;
</script>
is going to generate
baz = bar;
and bar
will be interpreted as an undefined variable name.
The proper solution is to simply pass everything through as json from PHP:
bar = <?php echo json_encode($foo); ?>;
which will ALWAYS produce valid javascript, no matter what's in $foo. and produces
baz = "bar";