I'm a javascript new comer so I apologize in advance if this is a "newb" question.
I'm making a web app that displays a google maps, map with a marker in your location. And then later more markers can be added to it using the add_marker function. A stripped down version of the code is:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="./common.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src=".\common.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function add_stops(lat,lng)
{
var loc = new google.maps.LatLng(lat,lng);
var marker = new google.maps.Marker
({
position: loc,
map: this.map,
marker: marker
});
}
</script>
<title>Local Stops</title>
</head>
<body>
<div id="map_canvas"></div>
<script type="text/javascript">initialize(null,null,16)</script>
<input type="button" id="10665" value="Stop 10665" onmouseover="add_stops(49.89995, -97.14124, 10665)"/>
<script type="text/javascript">add_stops(49.89995, -97.14124)</script>
</body>
</html>
My problem is the add_stops function wont run when called in the script tags in the body but it works fine when called by the onmouseover event for the button.
In short what would cause a function to run from an event but not when called from the body, and what can I do to fix it.
Thanks, any input is greatly appreciated.
**edited for spelling