Le Qs Le Qs - 1 month ago 15
Javascript Question

Variable in google maps infoWindow content fails

I have an infoWindow but i want to get the data from a variable but keeps failing whenever i try running the code

This is the code

Without the variable,this code works fine

content: "<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory


When i assign the content to a variable

var infoWindow = new google.maps.InfoWindow({
var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

content: kontent
});


i get
Unexpected token
error in the line
var kontent = ...


How can i correct my problem?.

Answer

infowindows: The InfoWindow constructor takes an InfoWindowOptions object literal, which specifies the initial parameters for displaying the info window.

This means, you need to change this:

 var infoWindow = new google.maps.InfoWindow({
        var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

        content: kontent
 });

To:

var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='
        "+mid+"
        ' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

var infoWindow = new google.maps.InfoWindow({
      content: kontent
});
Comments