0

I am using google maps and the infowindow that opens on the click of the marker calls a JavaScript function.
There is another function with multiple parameters that has to be called from this function.

The following is my code:

function createMarker(point,custid,streetadd,city,state,zip,address,phone,website,co) {         
    var infowindowHover,infowindowClick;

    var hoverText = "<CENTER><B>" + co + "</B></CENTER>";
    var markerMarkup = "<TABLE><TR><TD colspan='2'><B>";
    markerMarkup = markerMarkup + co + "</B></TD></TR><TR><TD colspan='2'>";
    markerMarkup = markerMarkup + streetadd + "</TD></TR><TR><TD colspan='2'>";
    markerMarkup = markerMarkup + city + "," + state + " " + zip + "</TD></TR><TR><TD colspan='2'>";
    markerMarkup = markerMarkup + phone + "</TD></TR><TR><TD colspan='2'>";
    if(website.indexOf("http://")>0) {
        markerMarkup = markerMarkup +"<a href=";
    } else {
        markerMarkup = markerMarkup +"<a href=http://";
    }
    markerMarkup = markerMarkup + website + " target=_blank>" + website + "</a></TD></TR><TR><TD>";                                
    var funCall = custid + "," + streetadd + "," + city + "," + state + "," + zip + "," + address + "," + phone + "," + website + "," + co;
    markerMarkup = markerMarkup + "<input type='button' class='button' value='see available styles' id='styles' onclick='setstyles("+ funCall +");'></input>";
    //markerMarkup = markerMarkup + "<input type='button' class='button' value='see available styles' id='styles' onclick='setstyles("+ custid +");'></input>"; 

    markerMarkup = markerMarkup + "</TD></TR></TABLE>";

    var marker = new google.maps.Marker({
        position: point,
        map: map,
        icon: image             
    });

    google.maps.event.addListener(marker, "mouseover", function () {
        if (infowindowHover) infowindowHover.close();
        infowindowHover = new google.maps.InfoWindow({content: hoverText});
        infowindowHover.open(map, marker);
    });

    google.maps.event.addListener(marker, "mouseout", function () {
        if (infowindowHover) infowindowHover.close();                
    });  

    google.maps.event.addListener(marker, "click", function () {
        if (infowindowClick) infowindowClick.close();
        infowindowClick = new google.maps.InfoWindow({ content: markerMarkup });
        infowindowClick.open(map, marker);
    });

    //google.maps.event.addListener(marker, "mouseout", function () {
    //    if (infowindowClick) infowindowClick.close();                
    //});
    return marker;
}

The second function that I want to call from this function is:

function setstyles(idcust,streetadd,city,state,zip,address,phone,website,co){
    var msg= "This feature is  available only to logged-in ";    
    alert(idcust);                     
    <%if Session("ctype")="1" then %>
        alert(msg + " non wholesalers.");
    <%else %>           
        <%if Session("ctype")="0" then %>
            var storestyles = 'storestyles.asp?id=' + idcust;         
            document.getElementById('storeaddresses').style.display = 'block';             
        <%else %>
             alert(msg + "users."); 
        <% end if %>
    <%end if %>
}

I want to pass the parameters from the createMarker() to the setstyles() which currently I am unable to do.

5
  • 2
    Why are you unable to call it? Commented Dec 5, 2012 at 13:01
  • There is a syntax error alert(stre Commented Dec 5, 2012 at 13:02
  • The syntax error has been solved. When I pass single parameter (custId) to setstyles() it works fine but when I pass multiple parameters the setstyles() it is not invoked at all. The bad part of the story is that there is no error thrown. Commented Dec 5, 2012 at 13:06
  • @Asad : I am not getting what you are asking me!! Commented Dec 5, 2012 at 13:08
  • Unrelated to the problem, but instead of markerMarkup = markerMarkup + X use markerMarkup += X. Commented Dec 5, 2012 at 13:10

2 Answers 2

2

In this line

var funCall = custid + "," + streetadd + "," + city + "," + state + "," + zip + "," + address + "," + phone + "," + website + "," + co;

If any of the parameters it's a string, you should be wrapping them into quotes.

For example, if city it's expected to be a string:

var funCall = custid + "," + streetadd + ",\"" + city + "\"," + state + "," + zip + "," + address + "," + phone + "," + website + "," + co;
Sign up to request clarification or add additional context in comments.

Comments

1

In this line:

    var funCall = custid + "," + streetadd + "," + city + "," + state + "," + zip + "," + address + "," + phone + "," + website + "," + co;

you simply build one huge string containing the variables separated by commas. So in this case you also commit only one parameter (the string). Try wrapping all the params into a parameter-object like that:

     var params = {
        custID: custid,
        streetAdd: streetadd,
        [...]
     }

and commit that to the function at onClick="setStyles(params)"...

The signature of setStyles should look like this: function setStyles(params){...}

Within setStyles you can access each parameter using sth. like params.custID or whatever you called the members of you parameter-object like....

Also consider the hints given in the comments below you question like using += which is considered good coding-style...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.