473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Create state-cty dropdown lists

I've gotten everything up and running except for this -- I'd like to
be able to have people have a dropdown list of cities in the US to use
(or wherever) and not have to input them manually into a text field.
When you do then there are issues of misspellings, etc.

Now I have a list of cities from each state that is a sample that
works in an html page. Problem is that it takes up 2 MB! Way too much
to load on a single page and I was wondering how this is accomplished
best -- do people use javascripts that can pull information from
another flat flie? Do people use PHP to connect to a mysql database
that might have a list of these fields and then reloads the page?

I'm really not sure of best options and would be grateful for anyone
to give me pointers or whether there are other examples and even
places to buy these databases (not likely but good to have if I decide
to do so.)
Jul 17 '05 #1
4 2015
Marc wrote:
I've gotten everything up and running except for this -- I'd like to
be able to have people have a dropdown list of cities in the US to use
(or wherever) and not have to input them manually into a text field.
When you do then there are issues of misspellings, etc.

Now I have a list of cities from each state that is a sample that
works in an html page. Problem is that it takes up 2 MB! Way too much
to load on a single page and I was wondering how this is accomplished
best -- do people use javascripts that can pull information from
another flat flie? Do people use PHP to connect to a mysql database
that might have a list of these fields and then reloads the page?

I'm really not sure of best options and would be grateful for anyone
to give me pointers or whether there are other examples and even
places to buy these databases (not likely but good to have if I decide
to do so.)

/*does all processing on genenric amounts of linked selects!!!
<script type="text/javascript">
<!--
selects=new Array();
selects[0]=document.forms['FrmAdminControl'].elements['test.0'];
selects[1]=document.forms['FrmAdminControl'].elements['test.1'];
selects[2]=document.forms['FrmAdminControl'].elements['test.2'];

initLinkedSelect(selects);
-->

requires following names on options so we know what goes where

<select name"=test.0">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
</select>
<select name="test.1">
<option value="dog-fido">Fido</option>
<option value="dog-rover">Rover</option>
<option value="cat-boots">Boots</option>
<option value="cat-pussy">Pussy</option>
</select>
<select> name="test.2">
<option value="dog-fido-dead">Dead</options>
....
....
</select>
*/

function initLinkedSelect(selects) {
var options = new Array();
var nextselect = new Array();
for (k = selects.length-2 ; k >= 0 ; k-- ){
from=selects[k];
to=selects[k+1];
options[from.name]=new Array();
(from.style || from).visibility = "visible";
for (var i=0; i < to.options.length; i++) {
options[from.name][i] = new
Array(to.options[i].text,to.options[i].value);
}

nextselect[from.name]=k;
from.onchange = function() {
to=selects[nextselect[this.name]+1];
var fromCode = this.options[this.selectedIndex].value+'-';
var selectedoption=0;
selectedoption=to.options[to.selectedIndex].text;
to.options.length = 0;
for (i = 0; i < options[this.name].length; i++) {
if (options[this.name][i][1].indexOf(fromCode) == 0) {
to.options[to.options.length] = new Option(options[this.name][i
[0],options[this.name][i][1]);
if(options[this.name][i][0]==selectedoption)
to.options[to.options.length-1].selected=true;
}
}
// to.options[selectedoption].selected = true;
if(selects[nextselect[to.name]] && selects[nextselect[to.name]].onchange
{
selects[nextselect[to.name]].onchange();
} else {

}
}
from.onchange();
}
}


--
Fletch
A: Because it disrupts the natural flow when reading
Q: Why is it bad to top post?
Jul 17 '05 #2
Marc <na**@quark.com> wrote:

I've gotten everything up and running except for this -- I'd like to
be able to have people have a dropdown list of cities in the US to use
(or wherever) and not have to input them manually into a text field.
When you do then there are issues of misspellings, etc.
Yes, but that's the only practical option. There will always be city names
(old names, variations, new names) that you don't have in your list. Will
you be able to handle Canadian cities, or European cities?
Now I have a list of cities from each state that is a sample that
works in an html page. Problem is that it takes up 2 MB! Way too much
to load on a single page and I was wondering how this is accomplished
best -- do people use javascripts that can pull information from
another flat flie? Do people use PHP to connect to a mysql database
that might have a list of these fields and then reloads the page?


No. People do not use dropdown lists for cities for precisely this reason.

If you're willing to pay the price for a zip code service, you could have
the user enter a zip code, then look up the cities and states for that zip
code, and present THOSE in a list. It would require a server round-trip,
but there are usually no more than a half-dozen city names for any single
zip.

Overall, it's probably easier to have users enter the city names they like,
and validate them later through the post office.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #3
On Tue, 22 Feb 2005 23:19:52 -0800, Tim Roberts <ti**@probo.com>
wrote:
Marc <na**@quark.com> wrote:

I've gotten everything up and running except for this -- I'd like to
be able to have people have a dropdown list of cities in the US to use
(or wherever) and not have to input them manually into a text field.
When you do then there are issues of misspellings, etc.


Yes, but that's the only practical option. There will always be city names
(old names, variations, new names) that you don't have in your list. Will
you be able to handle Canadian cities, or European cities?
Now I have a list of cities from each state that is a sample that
works in an html page. Problem is that it takes up 2 MB! Way too much
to load on a single page and I was wondering how this is accomplished
best -- do people use javascripts that can pull information from
another flat flie? Do people use PHP to connect to a mysql database
that might have a list of these fields and then reloads the page?


No. People do not use dropdown lists for cities for precisely this reason.

If you're willing to pay the price for a zip code service, you could have
the user enter a zip code, then look up the cities and states for that zip
code, and present THOSE in a list. It would require a server round-trip,
but there are usually no more than a half-dozen city names for any single
zip.

Overall, it's probably easier to have users enter the city names they like,
and validate them later through the post office.


Impossible. Too much work, plus the cleanup for misspellings would
make this a bear of a task. I could always use zip codes but then the
cities aren't really accurate in some instances since you can have
several different "towns" in one zip code. Not catastrophic but it
would be nice if this were easier.

Now I'd have to worry about dealing with putting an entire database of
zip codes into my database plus build in queries to join the zip code
table with the user table. I could always write a query to search the
zip code database and enter the town name into the user table for,
e.g. user.city to match user.zipcode . The fun part begins when you
want to perform a search and want the user to be able to choose by
city instead of just a zip code so I still have the issue of finding
the city name list for a drop down for users to search...
Jul 17 '05 #4
"Mike" <tkd__REM_OVE_SPA_M_inthecity@yahoo__SPAM_.com> wrote in message
news:ao********************************@4ax.com...

: Impossible. Too much work, plus the cleanup for misspellings would
: make this a bear of a task. I could always use zip codes but then the
: cities aren't really accurate in some instances since you can have
: several different "towns" in one zip code. Not catastrophic but it
: would be nice if this were easier.
:
: Now I'd have to worry about dealing with putting an entire database of
: zip codes into my database plus build in queries to join the zip code
: table with the user table. I could always write a query to search the
: zip code database and enter the town name into the user table for,
: e.g. user.city to match user.zipcode . The fun part begins when you
: want to perform a search and want the user to be able to choose by
: city instead of just a zip code so I still have the issue of finding
: the city name list for a drop down for users to search...

I missed the OP, but you'll need to do this on two pages (you could use an
IFRAME if you really *had* to I suppose...)

This is assuming you're selecting data from an existing list - it's no good
for inputting a new address.

1 - User selects state
2 - Submit form
3 - Return list of towns matching that state

As you said, a 2MB page is not practical, and no-one will thank you for it.

Matt
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dawnunder | last post by:
eg. Someone fills out 3 fields. (There will be more but this is just to give you an idea) 1. Country? 2. State? 3. City I want this script to generate a web page and list the people by
4
by: Max | last post by:
Hello everyone, and thank you in advance for all of your help! I have a tblPrint table in Access 2002. Its structure is as follows: tblPrint ------------------ Name, Text Address1, Text...
9
by: fishbaugher | last post by:
I have encountered some interesting crashes lately (Access97). Here is the symptom (after several days of different kinds of rebuilds including import and LoadFromText, all resulting in databases...
3
by: xenofex | last post by:
i have a xml file which include object name and its property. <objectname>TextBox1</objectname> <property>Text</property> how can i get the property source in c# ? . I have to create an object...
10
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung...
1
by: Jamie J. Begin | last post by:
I'm very new to the world of Python and am trying to wrap my head around it's OOP model. Much of my OOP experience comes from VB.Net, which is very different. Let's say I wanted to create an...
13
by: Bill Nguyen | last post by:
Is it possible to create your won XSD to use with .NET based on an XML content? For example the one below: <?xml version="1.0"?> <pcats:FuelsDoc...
0
by: TrevRex | last post by:
Hello, I work for a non-profit in San Diego as a GIS Specialist. I have had to teach myself about some scripting to create some dynamic maps, but I am still very limited in my skills, so I have...
5
by: firefighter17103 | last post by:
Hi All, I am new to MS Access 07, & do not know any VB, on a new business adventure. I am running Office07 on Vista Home Premium. Basically what I would like to do is create a database that I...
2
by: jarea | last post by:
I have read quite a bit about this error but I have yet to find the solution to my problem. I am trying to execute the following mysql statement: alter table line_items add...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.