Currently I have this code
function myFunction(arr)
{
var out = "<br />";
var i;
if(arr.length > 0)
{
for(i = 0; i < arr.length; i++)
{
out += "<div class='address container-fluid card svs-map-add' title='Show Location and Coordinates' onclick='chooseAddr(" + arr[i].lat + ", " + arr[i].lon + ");return false;'>" + arr[i].display_name + "</div>";
}
document.getElementById('results').innerHTML = out;
}
else
{
document.getElementById('results').innerHTML = "Sorry, no results...";
}
}
As you can see here I'm passing 2 variables and it contains latitude and longitude
onclick='chooseAddr(" + arr[i].lat + ", " + arr[i].lon + ");return false;'
These variables will go to function chooseAddr
Currently it's working fine
But now I need to include 1 more variable and it's
arr[i].display_name
Uncaught SyntaxError: Unexpected end of input
What I have done right now is
onclick='chooseAddr(" + arr[i].lat + ", " + arr[i].lon + ", \'" + arr[i].display_name + "\');return false;'
But there's an error with that syntax
How can I pass the display_name variable since this variable is String
onclick='chooseAddr(" + arr[i].lat, you are missing a single quote after the double quote, and the same to the rest of the concatenation. You used single quote to start the string, then every time you concatenate something, it must end also with a single quote. Plus you didn't tell us the error