Autofilling state and city based on zip code

user3361043

I am new to web development and I ran into an issue with a registration form that I'm building for our business. I am using this guide: http://css-tricks.com/using-ziptastic/. This is my first experience with AJAX and JSON and I just can't get the city and state to autofill as soon as I'm done typing in the zip code. Any solutions/suggestions/alternatives will be much appreciated. I set up a basic jsfiddle to test everything out: http://jsfiddle.net/7VtHc/

HTML:

<p>Zip Code: <input type="text" id="zip" /></p>
<p>City: <input type="text" id="city" /></p>
<p>State: <input type="text" id="state" /></p>

jQuery, etc.

$("#zip").keyup(function() {
var el = $(this);

if ((el.val().length == 5) && (is_int(el.val()))) {
    $.ajax({
    url: "http://zip.elevenbasetwo.com",
    cache: false,
    dataType: "json",
    type: "GET",
    data: "zip=" + el.val(),
    success: function(result, success)

    $("#city").val(result.city);
    $("#state").val(result.state);
    });
}
});
Ashley Medway

This should work for you. http://jsfiddle.net/7VtHc/5/
I will added that === in JavaScript will check that type are the same. See Here.
There is no need to create an is_int() function.

$(document).ready(function() {
    $("#zip").keyup(function() {
        var el = $(this);

        if (el.val().length === 5) {
            $.ajax({
                url: "http://zip.elevenbasetwo.com",
                cache: false,
                dataType: "json",
                type: "GET",
                data: "zip=" + el.val(),
                success: function(result, success) {
                    $("#city").val(result.city);
                    $("#state").val(result.state);
                }
            });
        }
    });
});

P.S. When you create a JSFiddle make sure you include jQuery from the menu on the right.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Autofill city and state from zip code in iOS

From Dev

Autofill City and State with Zip Code entry

From Dev

Parse Dataframe string column into Street, City, State & Zip code

From Dev

best data structure for country,state,city,zip-code hierarchy

From Dev

SQL Ranking Based on State and City

From Dev

Using zippopotam.us to auto-populate zip-code if user enters city and state

From Dev

Hide Show City and State when zip is populated

From Dev

Bing map need to display location border polygon based on city and zip code for DK

From Dev

Auto fill city after typing in zip code

From Java

Splitting address with various delimiters into street address, city, state, zip and country

From Dev

Regex for capturing City State Zip from an Address String

From Dev

Split 'City, State Zip' into three columns in pandas dataframe

From Dev

Bootstrap Inline Form Fields - City, State, Zip inline but with labels and not buttons

From Dev

Team city breaks build based on code coverage

From Dev

Auto fill country and city from zip code, and the oposite

From Dev

preg_match zip code & state not working

From Dev

dsmod or other command to edit AD user attributes (Street, P.O. Box, City, State, Zip)

From Dev

Python Doesn't Have Permission To Access On This Server / Return City/State from ZIP

From Dev

Aggregate by country, state and city

From Dev

State city dropdown list

From Dev

Country City State List

From Dev

Draw Hexagon based on zip code in google map?

From Dev

Using an API to get the Location based on ZIP Code

From Dev

How do I return the City, Street, and Zip Code of a google maps marker?

From Dev

Select similiar address records based on three columns(city+streetaddress+state) value along with join operation in mysql

From Dev

Select similiar address records based on three columns(city+streetaddress+state) value along with join operation in mysql

From Dev

When creating a user by Membership.CreateUser, is there a .NET wrapper that can set the user's address, city, state, zip, etc.?

From Dev

How to Find Neighboring States through State Zip code information in R

From Dev

Checking if selected state has the entered zip code jQuery

Related Related

  1. 1

    Autofill city and state from zip code in iOS

  2. 2

    Autofill City and State with Zip Code entry

  3. 3

    Parse Dataframe string column into Street, City, State & Zip code

  4. 4

    best data structure for country,state,city,zip-code hierarchy

  5. 5

    SQL Ranking Based on State and City

  6. 6

    Using zippopotam.us to auto-populate zip-code if user enters city and state

  7. 7

    Hide Show City and State when zip is populated

  8. 8

    Bing map need to display location border polygon based on city and zip code for DK

  9. 9

    Auto fill city after typing in zip code

  10. 10

    Splitting address with various delimiters into street address, city, state, zip and country

  11. 11

    Regex for capturing City State Zip from an Address String

  12. 12

    Split 'City, State Zip' into three columns in pandas dataframe

  13. 13

    Bootstrap Inline Form Fields - City, State, Zip inline but with labels and not buttons

  14. 14

    Team city breaks build based on code coverage

  15. 15

    Auto fill country and city from zip code, and the oposite

  16. 16

    preg_match zip code & state not working

  17. 17

    dsmod or other command to edit AD user attributes (Street, P.O. Box, City, State, Zip)

  18. 18

    Python Doesn't Have Permission To Access On This Server / Return City/State from ZIP

  19. 19

    Aggregate by country, state and city

  20. 20

    State city dropdown list

  21. 21

    Country City State List

  22. 22

    Draw Hexagon based on zip code in google map?

  23. 23

    Using an API to get the Location based on ZIP Code

  24. 24

    How do I return the City, Street, and Zip Code of a google maps marker?

  25. 25

    Select similiar address records based on three columns(city+streetaddress+state) value along with join operation in mysql

  26. 26

    Select similiar address records based on three columns(city+streetaddress+state) value along with join operation in mysql

  27. 27

    When creating a user by Membership.CreateUser, is there a .NET wrapper that can set the user's address, city, state, zip, etc.?

  28. 28

    How to Find Neighboring States through State Zip code information in R

  29. 29

    Checking if selected state has the entered zip code jQuery

HotTag

Archive