Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have three text fields, zip,city and state.Once the zip code is entered, then automatically the city and state should be auto-filled in the texboxes.
HTML
<label>ZipCode</label>@Html.TextBoxFor(x => x.Zipcode)
<label>City</label>@Html.TextBoxFor(x => x.City)
<label>State</label>@Html.TextBoxFor(x => x.State)

how can i do this, can anyone help
Posted
Updated 11-Oct-12 11:13am
v2

1 solution

You need to find some service which provides the ZIP code lookup. As I can see from your profile, you are in U.S., right? So, it could be like this one:
http://www.zip-codes.com/search.asp[^].

It would be more convenient to get a service with is provided as a Web service. Here is one:
http://www.webservicex.net/uszip.asmx[^].

This site provides dual service: you can do the ZIP code lookup through a Web browser as a human operator, or create a Web service client using provided WSDL, which the most convenient way to use the service in your code. I think, you will be able to find other services of this kind. You can do your search and refer to the documentation of the service provider on the services' sites.

If you are given WSDL, as in this case, the solution is quite easy. Please see:
http://msdn.microsoft.com/en-us/library/ms996486.aspx[^],
http://msdn.microsoft.com/en-us/library/6h0yh8f9%28v=vs.80%29.aspx[^],
http://msdn.microsoft.com/en-us/library/vstudio/7h3ystb6%28v=vs.100%29.aspx[^].

This is some walkthrough article showing how to consume such Web service, with examples:
http://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/[^].

If, by some reason, you need to use a "regular" Web site oriented for the use of a human operator using the browser, for a lookup of just about anything, you would need to use the techniques of Web scraping:
http://en.wikipedia.org/wiki/Web_scraping[^].

Please see my past answers:
get specific data from web page[^],
How to get the data from another site[^].

I hope you would not need it, because consuming a Web service is way better.

Good luck,
—SA
 
Share this answer
 
v4
Comments
Sushil Mate 11-Oct-12 12:34pm    
my 5 for your effort :)
Sergey Alexandrovich Kryukov 11-Oct-12 12:38pm    
Thank you, Sushil.
--SA
fjdiewornncalwe 11-Oct-12 17:13pm    
+5. Excellent.
Sergey Alexandrovich Kryukov 11-Oct-12 17:16pm    
Thank you, Marcus.
--SA
Member 9359591 12-Oct-12 12:19pm    
thnq so much..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900