I want to put a form with input field and submit button inside a Google Maps API (v3) InfoWindow.
When submitted I would like to call a function that initiates the directions service using the address entered into the input field.
Here's my code (I'm currently only testing whether the directions event is being fired. I've written the full getDirections()
event and can confirm it works and returns directions when fired properly):
I tried adding an event listener using MooTools, like this:
var infoWindowContent = "<b>Get Directions From...</b><br />"
+ "<form id='map-form'>"
+ "Address/Postcode: <input id='map-from-address' type='text' />"
+ "<input type='submit' id='map-go' value='Go' />"
+ "</form>";
var infoWindow = new google.maps.InfoWindow({
content: infoWindowContent
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map, marker);
dbug.log($("map-form"));
$("map-form").addEvent("submit", getDirections);
});
function getDirections(event)
{
dbug.log("getDirections");
event.stop();
}
As I'm using MooTools elsewhere in my site, I put all the code in window.addEvent('load', function(){...});
Note the console trace dbug.log($("map-form"));
which is correctly outputting the form element, but the event isn't firing.
I've added the same event to another form (with different ID) in the DOM and it works fine.
So, if MooTools can find the element and supposedly add the event listener, what's preventing the event from firing? Is this a scope issue?