views:

603

answers:

5

I want to do the following things using PHP and jQuery

https://www.careerbuilder.com/share/register.aspx?sc_cmp1=JS_LoginASPX_RegNow

Steps

  1. Select a country from a dropdown list.
  2. The city dropdown list will fillup automatically with the list of cities of the selected country.
  3. If state is available for that country then state list will be visible with all state list of that country.

Then I need to validate the selected city, state and country.

Do you have any ideas?

Thanks in advance

+5  A: 

If you want to make it easy for foreigners to enter an address, then please simply offer a text field, where the address can be entered as formatted text. Very few countries are using a state (or something similar) as part of the address and I don't understand why you want to offer a drop-down list with cities. A list of German cities (or more correct, valid place names in a postal address) would contain some 23,000 entries. What do you think is more easy, enter the address or try to find the place name in such a list_

jarnbjo
A: 

I'm facing a similar challenge. I don't know whether it's the case with you but in my case we need to be sure that the cities that are entered are really the existing ones. Later on in the project we want to be able to collect entries that are in the same city, anywhere in the world. And those results need to be precise. So we can't have people entering Philadelphia and Philly as well. And we also want people to use the English names for cities and not the names in their own language.

I've found some public databases of countries, states and cities. For instance here: MaxMind. But it's a list of roughly 3M cities and I've found another one of more than 6M. I've set it up exactly the way you describe. Select the country, then get the cities in it via an AJAX call and fill the dropdown. It takes about 2 seconds for a country like the Netherlands but the loading is just not acceptable for China or Russia for instance. And the lists are huge and not that user friendly at all.

So I suppose it's better to let people just enter them in a textfield when it's not that important that the cities really all match. We're looking at the Google Maps API right now to solve our problem.

Abel
Thanks abel for your nice suggestion. i have very near to a solution. as soon as i done with that, i will post it here. thanks once again.
M.M.H.Masud
A: 

This is a very standard AJAX scenario. In fact, the exact problem you describe is probably the single most common introductory Ajax example. You've listed PHP and jQuery as tags on your question; using these in concert will make the solution very simple.

My suggestion is to lookup jQuery Ajax examples with PHP. You'll almost certainly find exactly what you're looking for.

Brian Lacy
+1  A: 

What we do is use ServiceObjects.com to validate the address.

So we let the user enter their address in a plain text field (more or less), and then simply send the address details to ServiceObjects.com and use the normalized/corrected address returned by their webservice.

This isn't directly answering your question, but perhaps it provides an alternative solution to the root problem.

Alex Czarto
+1  A: 

Select a country from a dropdown list.

I assume this is an HTML SELECT populated from a database table.

The city dropdown list will fillup automatically with the list of cities of the selected country.

Don't do this. What you want is a jQuery Autocomplete, where the user starts to type and then you pull possible entries from your database.

If state is available for that country then state list will be visible with all state list of that country.

If you are doing mailing address validation, you only need this for a small number of countries. One common way of handling it is to have hidden SELECT boxes, and when the user picks a country (say, Australia) where you need to show the provinces, do it.

Then I need to validate the selected city, state and country.

Note that State/Province and Country are SELECT controls, so they should never have an invalid result, and validating city names is not possible.

egrunin