S
S
Sergey Goryachev2016-05-18 15:17:25
PHP
Sergey Goryachev, 2016-05-18 15:17:25

How to get value from PHP inside JS script?

I have a google map on my site.

<div id="map"></div>
<script>
  var map = new GMaps({
  el: '#map',
    lat: -12.043333,
    lng: -77.028333
  });
</script>

And in the admin panel there are $company_lat and $company_lng variables that store latitude and longitude.
How can I substitute these variables in the JS script?
It seems simple, but I just can’t figure it out, for some reason the coconut doesn’t grow :)))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-05-18
@webirus

<?php
...
?>
<div id="map"></div>
<script>
  var map = new GMaps({
  el: '#map',
    lat: <?=$company_lat ?>,
    lng: <?=$company_lng ?>
  });
</script>
<?php
...
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question