Google maps api Javascript add onclick to infowindow -


i tried add onclick infowindow after i'll click it show larger infowindow.

for i'm trying show alert having trouble it.

this infowindow code:

google.maps.event.addlistener(marker, 'click', (function (marker, i) {            return function () {                var name = locations[i][0];                infowindow.setcontent(name + '<button onclick="markercliked(name)">click</button>');                infowindow.open(map, marker);            }        })(marker, i)); 

and onclick function:

function markercliked(name){     alert("pressed on network " + name); } 

i'm getting error name not defined.

what doing wrong?

you're creating element looks

<button onclick="markercliked(name)">click</button> 

what "name" mean in context? nothing, function not in scope function tht created element, name means nothing

you do

infowindow.setcontent(name + '<button onclick="markercliked(\'' + name + '\')" >click</button>'); 

which creates

<button onclick="markercliked('value of name')">click</button> 

value of name actual value of variable name when button created ... want


Comments