1//passing PHP variable to JavaScript
2var myJSVar = <?php echo json_encode($myPHPVar); ?>;
1<?php
2$php_variable = 'string'; //Define our PHP variable. You can of course get the value of this variable however you need.
3?>
4 <script> js_variable_name = "<?php echo $php_variable; ?>";</script>
5