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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:50:28+00:00 2026-06-02T15:50:28+00:00

I have a form which collects some data, most importantly an address which needs

  • 0

I have a form which collects some data, most importantly an address which needs to be geocoded to obtain the lat and long.

Suppose the user inputs something like:

123 main st
SomEwheRE, NY 12345

My client-side javasript goes out to the Google Geocoding service and attempts to get the lat and long for that address. In return I also get back more addition information including the properly formatted address:

123 Main St
Somewhere, NY 12345

What I want to do is replace the values in their respective textboxes so that the user can verify the data is good and then finally submit via jQuery.post("My/Controller/", myJSONData, function(){}); but I’m getting some strange behavior.

If I type in an address and don’t include a zip code (it’s required in the database but not necessary to geocode the address) I get a validation error. The thing is I would like to defer validation until after I obtain the information from the geocode service and replace the values in the textbox.

Right now, if I only type in a partial address (and hit “Submit”) this is what happens:

  1. Validation errors occur on the missing required fields and all my textboxes go blank
  2. Hit submit again and this time the textboxes are properly filled in with the geocoded information BUT ALL fields produce validation errors.
  3. Hit submit a 3rd time and now the validation errors go away and everything is as expected. At this point, I want to consider the form valid and allow the POST to the Controller.

Code:

    $(document).ready(function () {
    $("form").submit(function (e) {
        e.preventDefault();
        var geoCodedAddress = geoCodeAddress($("#Address1").val(), $("#City").val(), $("#State").val());
        console.log(geoCodedAddress);
        geoCodedAddress.Name = $("#Name").val();
        geoCodedAddress.Phone = $("#Phone").val();
        $("#Address1").val(geoCodedAddress.Address1);
        $("#City").val(geoCodedAddress.City);
        $("#State").val(geoCodedAddress.State);
        $("#ZipCode").val(geoCodedAddress.ZipCode);
    });
});

geoCodeAddress() returns the JSON object with the required fields filled in and that works. I believe the problem lies somewhere between my ineptitude and the block of code I posted.

  • 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-02T15:50:29+00:00Added an answer on June 2, 2026 at 3:50 pm

    Well, after much tinkering this is what I came up with. Basically, when someone hits submit (or enter) I stop the form from being submitted (by e.preventDefault()) and check to see if it’s valid. If the form data is valid, I then process what the user entered, fill in the form fields with the acquired data (this doesn’t do anything functional, it just flashes the new data in the form). I couldn’t figure out how to submit the form, so I posted it myself using $.post(). If there is a better way please leave a comment or answer and I will vote. Here is my complete code:

        $(document).ready(function () {
        $("form").submit(function (e) {
            e.preventDefault();
            if ($("form").valid()) {
                geoCodeAddress($("#Address1").val(), $("#City").val(), $("#State").val(), function (geoCodedAddress) {
                    geoCodedAddress.Name = $("#Name").val();
                    $("#Address1").val(geoCodedAddress.Address1);
                    $("#City").val(geoCodedAddress.City);
                    $("#State").val(geoCodedAddress.State);
                    $("#ZipCode").val(geoCodedAddress.ZipCode);
                    $("#Longitude").val(geoCodedAddress.Longitude);
                    $("#Latitude").val(geoCodedAddress.Latitude);
                    $.post("/Controller/Action/", geoCodedAddress, function () { $(window).attr("location", "/Controller/"); });
                });
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an online form which collects consumer data and stores in a dedicated
I have some information which gets passed from a form and needs to be
I have a form which collects user info including name, location, url, email address
I have a form which collects a persons address. When they click submit I
I have a very simple GWT application which collects some data and provides a
I have a form on my website which collects data and posts using jquery
I have a form that collects information, one piece of which is a phone
I have an online form which collects member(s) information and stores it into a
I have a form which collects a name, password and email_address which are all
I have a form which collects basic user information. On the subsequent page it

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.