1

When I pass object through on mouseover, I did not get object data in function, and map web page stuck loading. This box text having image frame on map.

code:

function imagefream(Info) {

//Info having data(Info.Lat,Info.Long....etc)

    alert(Info.toSource()) //get all data of lat,lon,id..etc
    var boxText = document.createElement("div");
    boxText.innerHTML = '<div id=\"outer\" style=\"overflow: auto; cursor: default; clear: both; position: relative; background-color: rgb(0, 136, 204); border-color: rgb(0, 136, 204); border-style: solid; border-radius: 5px; border-width: 1px; padding: 3px; width: 50px; height: 50px;\"  onMouseOver=\"funinfo(' + Info + ');\" >' +
        '</div>';
    return boxText;
}

function funinfo(Info) {
    alert("123");
    alert(Info.toSource());
}
3
  • 2
    can you also include the event handler code? Commented Mar 25, 2014 at 18:19
  • 1
    You don't need to escape your double-quotes if they are inside single quotes. Also, just put the closing div on the same line instead of trying to concat. And you could have your style rules in a CSS file and use the id instead of adding it inline. Commented Mar 25, 2014 at 18:24
  • thanks..removed quotes its worked thanks... Commented Mar 26, 2014 at 20:21

2 Answers 2

2

You are concatenating an string to an object-> '...onMouseOver=\" funinfo('+Info+');\"...'

It will generate something like that -> 'onMouseOver="funinfo([object Object]);"'

Seems that what you wanna do is call the function funinfo passing the object Info, so thats what you need in your onMouseOver property. Your code should looks like that -> 'onMouseOver=\" funinfo(Info);\"'. No need to concatenate the object.

Note that Info should be in your window, or global space.

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

2 Comments

'.......onMouseOver=\"funinfo(Info);\" >' <--- i tried like this but no use i did not get alert("123") when cursor on imagefream(image on map). please help.
i given var imageinfo=Info; '...onMouseOver=\" funinfo(imageinfo);\">'; i tried like this also.
1

Here is solution for your problem. Notice i am declaring a namespace

    var myNamespace = myNamespace || {};
$(document).ready(function(){   
    myNamespace.info = {Lat: 42.123456789, Lng: -41.123456789}; // some object
    myNamespace.funinfo = function (Info) {
    console.log("logging from funinfo: " + Info.Lat + "," + Info.Lng);
}
    myNamespace.imageFrame= function(Info){
    myNamespace.info = Info;
    console.log("logging from imageFrame: " + myNamespace.info.Lat + "," + myNamespace.info.Lng);
    var boxText = document.createElement("div");
    boxText.innerHTML = '<div id=\"outer\" style=\"overflow: auto; cursor: default; clear: both; position: relative; background-color: rgb(0, 136, 204); border-color: rgb(0, 136, 204); border-style: solid; border-radius: 5px; border-width: 1px; padding: 3px; width: 50px; height: 50px;\"' +
    'onMouseOver=\"myNamespace.funinfo(myNamespace.info);\" >' +
        'MyDIb</div>';
    return boxText;
}
    var d = myNamespace.imageFrame(myNamespace.info);
    document.body.appendChild(d);   

});

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.