Reputation: 317
I am getting below error when I am trying to call infoBox.open method in my page.
Microsoft JScript runtime error: Invalid value for property : [object Object]
The following is the code which I am using.
var myInfoOptions = {
content: 'Test'//$extradiv.html()
, closeBoxMargin: "12px 2px 2px 2px"
, closeBoxURL: '/Images/infowindow-close.gif'
};
var ib = new InfoBox(myInfoOptions);
var info_Marker = new google.maps.Marker({
position: new google.maps.LatLng(e.latLng.lat(), e.latLng.lng())
});
info_Marker.setMap(null);
ib.open(map, info_Marker);
I have declared Map object globally and binding the data as below.
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
Hoping for quick response.
Thanks,
Kalyan Basa
Upvotes: 2
Views: 1798
Reputation: 117334
Just a guess:
What happens: IE
Here is the problem: When you don't declare the variable before the element is parsed, you cannot overwrite the reference to the element.
A demo for better understanding:
Attempt#1:
<input id="foo" type="button" value="click me to see foo's type-property" onclick="fx()">
<script>
function fx()
{
alert(foo.type);
}
window.onload=function()
{
foo={type:'this is the type-property of the foo-variable'};
}
</script>
...the input#foo is parsed before the variable is created. The attempt to create the variable foo will fail in IE, because there already exists the reference to the input#foo accessible in global scope. The alert will return "button", the type of the input#foo
http://jsfiddle.net/doktormolle/kA9nb/
Attempt #2:
<script>
var foo;
function fx()
{
alert(foo.type);
}
window.onload=function()
{
foo={type:'this is the type-property of the foo-variable'};
}
</script>
<input id="foo" type="button" value="click me to see foo's type-property" onclick="fx()">
As you can see, the variable foo is declared in global scope, before the input#foo is parsed.
IE now will not create the global reference to input#foo and everything works as expected:
http://jsfiddle.net/doktormolle/88QV8/
So the solution: declare the variable "map" inside the global scope.
Upvotes: 1