How to add Search Functionality in Registration form?

Hi there

I want to add search functionality like for City and State ,country.How Can I Implement it.

I am using Java(JSP,Servlets) as my server side lenguage

I have heared about

But what are the other ways to add search functionality like custom searchs and other?


Sorry if this is off-topic, but when / why would you want Search in a Registration form?


let me explain this is my registration form

Under Current Address->City I want to show search suggestion like I am living in India so if someone type “De” then I will show(Delhi,Delaram Market,Old Delhi,New Delhi…etc)

both prefix and suffix matching.

I hope you got my point.

Ah, OK.

I wouldn’t call that a Search but
“suggested auto-complete”
though I don’t think that’s the correct term either.

Where are the city names coming from, a database?
Is it extensive or would an array or CSV file be adequate?

yeah that’s correct

“suggested auto-complete”

Where are the city names coming from, a database? Is it extensive or would an array or CSV file be adequate?

I am not able to decide(I am beginner in web development).I have 10,000 name of cities. what is best way to store this type of data?

I would consider 10000 extensive. Way too many for me to want to have to update in an editor every time it needed some added or deleted.

If you have these city names in a file, I would parse the names out and create a database table (or maybe a CSV file) that could be edited from a script. (assuming PHP here).

I think a database table would be faster as you could “index” the names.

Then I would use AJAX to go to a server-side file that looks for names that “match” the input value and returns them.
But I likely wouldn’t do it until at least a few letters had been entered

Can you provide some codesnipshot or a sample link where I should start?

Got a sample of what wherever the names are looks like?
* a few lines should be enough, not all 10000 please.

Here is list sample

Lohaghat,Uttarakhand Lohawati,Uttarakhand Champawat,Uttarakhand Pithoragah,Uttarakhand Sitarganj,Uttarakhand Chambal,Madhya Pradesh Karolbagh,New Delhi Bandra,Maharastra Pune,Mahrastra Kormangla,Banglore Sectore-63,Nodia Sectore-65,Noida Sector-98,Gurgaon Kanpur,Uttar Pradesh Lucknow,Uttarapradesh Muzzafarnagar,Uttarapradesh Meerut,Uttara Pradesh Shamali,Uttar Pardesh Hisar,Hariyana Chandigarh,Punjab Nahan,Himanchal Pradesh

if this is not sufficinet I will add more I have 10,000 entry in this order and sequence

Somewhere to start could be to look at jQuery’s autocomplete from a remote data source, where effectively you have a server-side script that performs database lookup based on the provided search term.

That’s plenty.

It is a CSV file with 2 “columns” City and State

If you try


$csv_file = "<path to file / filename here>";
if (($handle = fopen($csv_file, "r")) !== FALSE) {
    $city_state_arr = [];
    $csv_line = 0;
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
	$city_state_arr[$csv_line]['city'] = $data[0];
	$city_state_arr[$csv_line]['state'] = $data[1];
echo "<pre>";
echo "</pre>";

Do you get them all or does it time out or throw any errors?

That was my thinking too, but the info will need to get into a database at some point.

@Mittineague @Paul_Wilkins Thanks to both of you

I will try both of your suggestion and will come back with my original code after some time

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.