javascript - How to access .js function in html? -


my experience in javascript lacking terribly.. , 1 question alone solve 90% of problems @ current!

so here have map displays, , marker langlat placed in .js file, require able add markers through php, i'm assuming i'll have pass array foreach , run script add each marker. accessing function appears main issue.

<div class="col-md-6">     <div class="content-wrap" id="map">          <div class="wrapper" >         </div>      </div> </div>   <script src="js/maps.js"></script> <script src="plugins/gmaps.js"></script> 

maps.js

var googlemap = function () {      var map;      return {         init: function () {             map = new gmaps({                 div: "#map",                 lat: ***,                 lng: ***             });             map.addmarker({                 lat: ***,                 lng: ***,                 title: "marker infowindow",                 infowindow: {                     content: "<p>***</p>"                 }             });         }     }; }();  $(function () {     "use strict";     googlemap.init(); }); 

how reach function in .php file?

also note, current map markers in .js function work correctly.

you cant reach .js file php script, unless want make heavy ugly function rewrite file every load.

make inline-script in html file instead.

replace:

<script src="js/maps.js"></script> 

with:

<script type="text/javascript"> var googlemap = function () {      var map;      return {         init: function () {             map = new gmaps({                 div: "#map",                 lat: <?php echo $lat; ?>,                 lng: <?php echo $lon; ?>             });             map.addmarker({                 lat: <?php echo $lat; ?>,                 lng: <?php echo $lon; ?>,                 title: "marker infowindow",                 infowindow: {                     content: "<p>***</p>"                 }             });         }     }; }();  $(function () {     "use strict";     googlemap.init(); }); </script> 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -