Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:48:43+00:00 2026-05-23T06:48:43+00:00

I want to put a form with input field and submit button inside a

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:48:44+00:00Added an answer on May 23, 2026 at 6:48 am

    it does not look like a scope issue. getDirections is in the same scope.

    this is an egg vs chicken case. ultimately – your string of html is not in the DOM so you cannot add events to it just yet or reference elements from it. the info window is slightly asynchronous so you need to make sure the content div is attached. Or, you need to use Event delegation.

    the event pattern google provides comes in handy to attach the submit handler on the div’s domready like so:

    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>"
    ].join("");
    
    
    var info = new google.maps.InfoWindow({
        content: infoWindowContent
    });
    
    google.maps.event.addListener(info, 'domready', function() {
        document.id("map-form").addEvent("submit", function(e) {
            e.stop();
            console.log("hi!");
        });
    });
    
    info.open(map, marker);
    

    tested and working. alternatively, you can attach the content sting into the dom as child of some hidden div, add the event and then pass on the div as the content as it supports being pointed to a node.

    https://developers.google.com/maps/documentation/javascript/infowindows

    alternatively, you can use event delegation

    eg.

    topnode.addEvent('submit:relay(#map-form)', function(e){ }); – or the equivalent jQuery, for instance $(document).on('submit', '#map-form', fn)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to put a button inside text like this one: some text1
Once a form is submitted, I'd like to get the value of a field
i want to put the value of id field of $info in my form's
If I want to put a form up on SharePoint, is it easier to
I want to insert a group box in the form and put in 3
I have a form with two input fields and a tag cloud. I want
In one of my views I got an INPUT field where I put my
I have a form. The form contains a text field inside of a div.
I want to update a field in my html form separately from the rest.
I have a Zend_Form_Element_Multicheckbox and I want to put some of its elements in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.