I'm trying to pass a value via PHP to a Javascript function but it isn't working, the value doesn't appear to be going through. When I replace the variable with static text, it works fine.
I'm calling the function via a PHP file like so..
<?php
if (!empty($data['geocode'])) {
echo '<body onload="initializeGM(\'' . $data['geocode'] . '\');">';
} else {
echo '<body>';
}
?>
$data['geocode'] contains both the lat and lng as a string.
Here is the Javascript code..
function initializeGM(geocode) {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(geocode),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
I have added an alert(geocode) into the JS function to test and it works fine.
How can I make it so I can pass the geocode variable in and it works?
$data['geocode']typically look like?