hari86
hari86

Reputation: 669

Infowindow with buttons

Hi iam trying to put buttons in the infowindow and when i click the button some action should takeplace atleast an alert.below is my code

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    function initialize() {

        var mapOptions = {
            zoom: 7,
            center: new google.maps.LatLng(12.98,77.59),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById('map'), mapOptions);

        var infoWindow = new google.maps.InfoWindow();

        (function() {
            var marker = new google.maps.Marker({
                map: map,
                draggable: false,
                position: new google.maps.LatLng(12.98,77.59)
            });
            var content =   "<div id='tabs'>"+
                            "<form id='button'>"+
                            "<div>"+
                            "<input type='button' onclick='alert(infoWindow)'>"+
                            "</div>"+
                            "</form>"+
                            "</div>";  
   google.maps.event.addListener(marker, 'click', function(event) {
                infoWindow.setContent(content);
                infoWindow.open(map, marker);
            });
        })();

    };
  </script>
  </head>
  <body onload="initialize()">
    <div id="map" style="width:400px; height:300px"></div>
  </body>
  </html>

here i can add the button but not able to make it work..Any help would be appreciated

Upvotes: 2

Views: 7075

Answers (2)

kaskader
kaskader

Reputation: 1972

If you want to get more out of InfoWindows and put HTML content in them I would recommend trying InfoBox. Check out the reference here

It has some of the additional things like closing the window build in.

Upvotes: 0

Pratik
Pratik

Reputation: 30855

you pass the value in the alert() as variable not as string. You need to pass this within single or double quote

var content =   "<div id='tabs'>"+
                "<form id='button'>"+
                "<div>"+
                "<input type='button' onclick='alert(\"infoWindow\")'>"+ // here
                "</div>"+
                "</form>"+
                "</div>";  

now try with this.

Upvotes: 2

Related Questions