-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
  • 15,128
  • 9
  • 44
  • 66
Ahmed Wael
  • 29
  • 10

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
  • 546
  • 5
  • 17
Jim-miraidev
  • 1,658
  • 1
  • 9
  • 22
0
infoWindow.setContent(data.name+ "<input type=button onClick=Myfunction("+ data.name +") />");
S.I.
  • 2,891
  • 11
  • 38
  • 58
Sultan Khan
  • 288
  • 1
  • 10