0

I have below code but nothing happens when a zip code is entered, what is wrong here?

html

<asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox>        
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox> 
<asp:TextBox ID="txtState" runat="server"></asp:TextBox> 

script

<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $("input[id$='txtZipCode']").keyup(function () {
            var el = $(this);

            if (el.val().length === 5) {
                $.ajax({
                    url: "http://zip.getziptastic.com/v2/US/" + el.val(),
                    cache: false,
                    dataType: "json",
                    type: "GET",
                    success: function (result, success) {
                        $("input[id$='txtCity']").val(result.city);
                        $("input[id$='txtState']").val(result.state);
                    }
                });
            }
        });
    });
</script>
7
  • Perhaps your ajax call is not succeeding? Have you attempted to debug this? Commented Jun 12, 2014 at 19:11
  • Why don't you share the fiddle? Commented Jun 12, 2014 at 19:13
  • @DanielCook jsfiddle.net/7VtHc/117 Commented Jun 12, 2014 at 19:16
  • Unfortunately, your fiddle doesn't work in my browser (IE10) hopefully it'll work for someone else. Commented Jun 12, 2014 at 19:24
  • @DanielCook Now that you mention that, I realized that just work on Chrome :( any idea on how to make it work on IE, mine is IE8 Commented Jun 12, 2014 at 19:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.