i was writing some code in javascript and i need it to work on most browsers but it only works in googleChrome, IE and FF dont call this function:
<script type="text/javascript">
showLocation(<?php print "\"$citta2\""?>,<?php print "\"$row[nome] $row[cognome]\""?>,<?php print "\"$row[id]\""?>); return false;
</script>
(i know that it doest call it because the 1st thing that its suppoed to do is make an allert) do u know of any reason why that would work only in chrome? if you need the all file i can post it below but its a bit long, also I'm positive that the problem is in that call.
edit1: here is showLocation code:
function showLocation(address2,nomi0,id0) {
alert("1");
var nomi1 = nomi0;
var id1 = id0;
geocoder.getLocations(address1, function (response) {
if (!response || response.Status.code != 200)
{
alert("Errore con il primo indirizzo");
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(address2, function (response)
{
if (!response || response.Status.code != 200)
{
alert("Errore con il secondo indirizzo");
}
else
{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
calculateDistance(nomi1,id1);
}
});
}
});
}
(it uses google maps api to get latitude and longitude of a city)
Not an answer(as of yet) just need more than the 600 characters allowed in comments.
First, lets make your script tag a little easier to read, and add some debugging:
<script type="text/javascript">
try {
if (window.showLocation)
{
showLocation(<?php print "'{$citta2}','{$row[nome]} {$row[cognome]}','{$row[id]}'"; ?>);
}
else
{
// if you see this message:
// then you have a syntax error before or within the creation of showLocation
alert("showLocation has not been created!");
}
}
catch (e) {
alert("Error from caller: " + e);
}
</script>
And now in your other code, add some debugging:
function showLocation(address2,nomi0,id0) {
try {
alert("1");
var nomi1 = nomi0;
var id1 = id0;
geocoder.getLocations(address1, function (response)
{
try
{
if (!response || response.Status.code != 200)
{
alert("Errore con il primo indirizzo");
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(address2, function (response)
{
try
{
if (!response || response.Status.code != 200)
{
alert("Errore con il secondo indirizzo");
}
else
{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
calculateDistance(nomi1,id1);
}
}
catch (e)
{
alert("Error in callback#2: "+ e);
}
});
}
}
catch (e)
{
alert("Error in callback#1: " + e);
}
});
}
catch (e)
{
alert("Error in functon: " + e);
}
}
_Added even more debug alerts_