Jump to content

Passing php variable on a javascript


frank_solo

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.