java script - Cant send parameter to function from info window in google map marker info window

Posted by drdigital on Stack Overflow See other posts from Stack Overflow or by drdigital
Published on 2012-11-05T16:15:03Z Indexed on 2012/11/05 17:00 UTC
Read the original article Hit count: 299

I'm showing up some markers on a map. when clicked, an info window appear. this window contains 2 button each send ajax request. the problem is that when I send any thing (Except a marker parameter below) to the button onClick event it does not work. and I get the error "adminmap.html:1 Uncaught SyntaxError: Unexpected token ILLEGAL" on the first line of the HTML page not the script file at all.

function handleButtonApprove(id) {
    //error happens here when I send any parameter except marker8(defined below)
    //console.log(id);
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: VERIFY_OBSTACLES_URL,
            //data: { markerID:sentID , approved:0 },
            success: function (data) {
                alert(data);
            }
        });
    });
}

function handleButtonReject() {
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: VERIFY_OBSTACLES_URL,
            //data: { markerID:marker.id , approved:0 },
            success: function (data) {
                alert(data);
            }
        });
    });
}

function attachInfo(marker8, num) {
    //var markerID = marker.get("id");
    //console.log(markerID);
    var infowindow = new google.maps.InfoWindow({
        //Here is the error , if I sent num.toString, num or any string , it does not work. If send marker8.getPosition() for example it works. May I know the reason ?
        content: '<div id="info_content">Matab Info</div> <button onclick="handleButtonApprove(' + num.toString() + ')">Verify</button> </br> <button onclick="handleButtonReject()">Remove</button>'
    });
    google.maps.event.addListener(marker8, 'click', function () {
        infowindow.open(marker8.get('map'), marker8);
    });
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-maps