I have the following code in the body
<div id="searchresult" onmouseover="changeMarker(marker1)">
and the following in the head
function changeMarker(marker) {
alert(marker);
}
Now when i mouseover the div, I get the following error in the javascript console
Uncaught ReferenceError: marker1 is not defined
If I have the following instead, where the function does not take variables, the alert box is called.
function changeMarker() {
alert('hi');
}
<div id="searchresult" onmouseover="changeMarker()">
Did I make a mistake somewhere?
EDIT
I forgot I defined marker1 within initialize() as follows (I'm using google maps v3 api)
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(1.288693,103.846733),
map: map,
icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=1|c41200|ffffff"
});
This is the rest of the code I'm really using:
<div id="searchresult" onmouseover="changeMarker(marker1)">
and the function is
function changeMarker(marker) {
var icon = new Google.maps.MarkerImage({ url:"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=1|ffffff|c41200"});
marker.setIcon(icon);
}
I get the same error: Uncaught ReferenceError: marker1 is not defined
marker1anywhere so how does it know what to pass? You never told it what the variablemarker1is. If you are trying to send a string to your function then it needs quotes around it:<div id="searchresult" onmouseover="changeMarker('marker1')">marker1defined global? Is it in ascripttag that comes before thedivtag?