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 8782645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:37:10+00:00 2026-06-13T20:37:10+00:00

I want to trigger a function when the submit button is pressed on the

  • 0

I want to trigger a function when the submit button is pressed on the form and wait for the javascript function to complete, then continue the form submission. I dont want the form to submit before the javascript function has completed.**

This is what I have at the moment:
http://jsfiddle.net/njDvn/68/

function autosuggest() {
var input = document.getElementById('location');
    var options = {
    types: [],
    };
    var autocomplete = new google.maps.places.Autocomplete(input, options);
}

<!-- Get lat / long -->      
function getLatLng() {
    var geocoder = new google.maps.Geocoder();
    var address = document.getElementById('location').value;
    geocoder.geocode({
        'address': address
    }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var latLng = results[0].geometry.location;
            $('#lat').val(results[0].geometry.location.lat());
            $('#lng').val(results[0].geometry.location.lng());
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
}

<!-- Load it --> 
window.onload = autosuggest;
  • 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-06-13T20:37:11+00:00Added an answer on June 13, 2026 at 8:37 pm

    You can intercept the form submission, abort it and send the geocoding request to Google.

    When the server responds, you can re-submit the form from the callback (or display an error in case of failure).

    Store the state of the request somewhere (for the sake of simplicity, I’m using a global variable in my example). In this case, it’s just a flag that indicates whether or not the geocoding request was completed successfully (so that now, when the form is submitted and the listener is re-triggered, it will know not to re-send the geocoding request).

    http://jsfiddle.net/njDvn/75/

    Feel free to remove the console logging.

    You may also want to make the lat/long fields hidden.

    var GeoCoded = {done: false}; // this holds the status of the geo-coding request
    
    $(document).ready(function(){
        autosuggest(); // place your auto-suggest (now called autocomplete) box
    
        $('#myform').on('submit',function(e){
    
            if(GeoCoded.done)
                return true;
    
            e.preventDefault();
            console.log('submit stopped');
            var geocoder = new google.maps.Geocoder();
            var address = document.getElementById('location').value;
    
            // disable the submit button
            $('#myform input[type="submit"]').attr('disabled',true);
    
            // send the request
            geocoder.geocode({
                'address': address
            },
            function (results, status) {
                // update the status on success
                if (status == google.maps.GeocoderStatus.OK) {
                    var latLng = results[0].geometry.location;
                    $('#lat').val(results[0].geometry.location.lat());
                    $('#lng').val(results[0].geometry.location.lng());
                    // if you only want to submit in the event of successful 
                    // geocoding, you can only trigger submission here.
                    GeoCoded.done = true; // this will prevent an infinite loop
                    $('#myform').submit();
                } else { // failure
                    console.log("Geocode was not successful for the following reason: " + status);
                    //enable the submit button
                    $('#myform input[type="submit"]').attr('disabled',false);
                }
    
    
            });        
    
        });   
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to trigger on click of a button this: <asp:Button runat=server ID=submit Text=Submit
I've got a form with a custom submit button (not an input[type=submit]). I want
I want to trigger a specific input button in a form from another forms
If I want to trigger an error in my interpreter I call this function:
I have an click function that I want to trigger outside of the function
I have $('#myElem').mouseup(function(e){ isMouseDown = false; }); What I want to do is trigger
I want to trigger an event with a button that changes the visibility of
I want to trigger javascript alert using PHP. Is it possible I want to
Hi I want to validate a form using a button, but this button call
At this all evening and can't see what I'm missing: JS: $(document).ready(function() { $(#form).submit(function

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.