frank_solo Posted March 4, 2013 Share Posted March 4, 2013 How can I pass a variable onto a javascript. Trying to use google maps. Trying to get the variable cross_streets to work on the google maps script. Any other way of doing this? <div id="map" align="center" style="width:300px; height:300px"> <div align="center"> <?php $cross = $result['cross_streets']; ?> <script type="text/javascript"> $(function() { $("#map").gMap({ markers: [{address:"'<?php echo $cross ?>', New York, NY"}],zoom: 15}); }); </script> </div> Link to comment https://forums.phpfreaks.com/topic/275211-passing-php-variable-on-a-javascript/ Share on other sites More sharing options...
trq Posted March 4, 2013 Share Posted March 4, 2013 What you have done should work, what does the output look like? Link to comment https://forums.phpfreaks.com/topic/275211-passing-php-variable-on-a-javascript/#findComment-1416414 Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 Your method of inputting a PHP variable into your javascript is fine. Looking at your JS, it looks like you may have some issues there (which is probably why it's not working), but that's a different topic than this one (which is how to insert PHP variables into JavaScript). Are you able to the output of your php variable when you look at the HTML page source? Link to comment https://forums.phpfreaks.com/topic/275211-passing-php-variable-on-a-javascript/#findComment-1416415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.