-2

Im trying to pass a variable into an inline onclick function but without success. i've tried searching and i followed this but with errors(Uncaught SyntaxError: missing ) after argument list) : pass string parameter in an onclick function

google.maps.event.addListener(marker, "click", function(e) {
infoWindow.setContent(data.name+ "<br> '<input type="button"onClick="Myfunction(\'' + data.name + '\')" />');
infoWindow.open(map, marker);
});

I want to pass data.name results inside My function(data.name);

Another thing that i want to process this result inside myfunction to load an image from Mysql php database shall i use Ajax?

Marcus Höglund
  • 16,172
  • 11
  • 47
  • 69
Ahmed Wael
  • 29
  • 11

2 Answers2

0

The error was caused because your string was invalid:

google.maps.event.addListener(marker, "click", function(e) {

    var contentString = '<h3>'+data.title+'</h3></br><input type="button"onClick="Myfunction(' +data.title+ ')" />';

    infoWindow.setContent(contentString);                
    infoWindow.open(map, marker);    
});
Jay Buckman
  • 581
  • 5
  • 18
DesignMonkeyJim
  • 1,875
  • 1
  • 10
  • 23
0
infoWindow.setContent(data.name+ "<input type=button onClick=Myfunction("+ data.name +") />");
S.I.
  • 3,250
  • 12
  • 48
  • 77
Sultan Khan
  • 308
  • 2
  • 11