Location form problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi all,

I have the following dilemma, which is probably a pretty common dillema.

I have a database with countries and cities (downloaded GeoSource Free
Edition). If somebody registers on my site I would like them to select a
country and city (not manditory, but for the purpose of the site,
advisable). This functionality will also appear in other parts of the site
as a search function.

The countries can be put in a select box, no problem. But some countries
have over 100.000 cities. Not something you put in select box.

So I've played around with a text field for the city and with the use of
AJAX suggest, say the first 20, cities, that match what the user has typed
so far. User selects suggestion > textfield gets filled. Works like a charm.
But a user can still put in any name he/she likes and submit the form. What
I'm aiming for is to make the form a little more bulletproof, in that I
capture the city id, in stead of having to search the database again to
check if the city name the user submitted does exist.

As you understand, this would have been easy with a select box.

My own thoughts so far suggested something like:

- Have a textfield and let user input a few characters and populate a select
box from there.
- Have a selectbox with say max 50 options and the last and first options
(if applicable) populate the next / previous 50 options.

But these solutions seem cumbersome. So before I try to hack these
approaches I'ld like to here some other opinions.

What would you suggest for this dillema? Any (relevant ;-) approach is
welcome, not per se these type of AJAX approaches.

Of course, if anybody knows of any free available database with only the
major / important cities of their respective countries and / or cities
subcategorized by region / provence / state / etc., that would help a fair
amount too :)

Thanks in advance for your help and suggestions!


Re: Location form problem

Quoted text here. Click to load it

If you're already sending the city names via AJAX, why can't you send
ids along with them?

http://NikitaTheSpider.com /
Whole-site HTML validation, link checking and more

Re: Location form problem

Quoted text here. Click to load it


Thanks for the reply.

Sorry, forgot to mention that I'm already sending the id's along. But I
somehow want to 'force' the user to choose a suggested city so that an id
gets set. Just like a select box option. In stead of giving them suggestions
that they can ignore. Maybe my whole approach here is somewhat buggy.

The way the AJAX thingy works is:

The user can click on a suggestion, and the id gets set. But a user can also
select a suggestion by using arrow keys, in which case strangely enough only
the textfield get filled with the suggestion but no id gets set (with a
little hack I could probably fix that). What's more, if the user presses
enter while scrolling through the suggestions, the form gets send.

So in a nutshell, the ideal thing I'm looking for is a selectbox that
accepts user input (typing a few chars) and the selectbox dynamically gets
filled with suggestions. And a user _has_ to choose a suggestion.

Site Timeline