Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.