Javascript variable define problem -- maybe scope issue?
Posted: Thu Jul 20, 2006 10:00 am
Weirdan | Please use
Weirdan | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm confused as to how to get an argument from one function to another... or how to solve my issue here. When I run this, it throws a js error "marker is undefined". Anyone have any thoughts as to how I could get this loop to work?I'm trying to pass the info into the text "bubbles" that appear when you click on the marker.
[syntax="javascript"]
var map = null;
var geocoder = null;
<?php
$key = 0;
foreach($results as $key => $contact) {
$results[$key][javavarname] = "address$key";
$varString = "var address$key = \"$contact[address1], $contact[city], $contact[state], $contact[zip]\";\n";
echo $varString;
$key++;
}
?>
function markAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
// alert(address + " not found");
} else {
map.setCenter(point, 7);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
}
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder();
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
<?
foreach($results as $contact) {
echo "markAddress(" . $contact[javavarname] . ");\n";
echo "GEvent.addListener(marker, \"click\", function() {\n";
echo "marker.openInfoWindowHtml(" . $contact[javavarname] . ");\n";
echo "});\n";
}
?>
}
}Weirdan | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]