2

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

4
  • in which line throws the error?. Second try to add the event handler with the listener Commented Jun 7, 2012 at 13:36
  • Why are you doing this: "info_Marker.setMap(null);"? Seems like that would be a problem. Why not "info_Marker.setMap(map);"? Commented Jun 7, 2012 at 13:55
  • Jorge - I am getting error on this line "ib.open(map, info_Marker);" <br/> geocodezip - I am using setMap(null) because I don't want to display marker on the map. Commented Jun 8, 2012 at 6:15
  • This works for me: jsfiddle.net/xCSuk/9. Not sure what your issue is, a link to your map or a working demo of the problem would be more useful. Commented Feb 19, 2015 at 0:19

1 Answer 1

1

Just a guess:

  1. you don't declare the variable "map" inside the window's scope
  2. somewhere inside the document is an element with the ID "map" or a form, image, anchor etc. with the name "map"

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.