473,395 Members | 1,745 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,395 software developers and data experts.

Automatically populate a pull down list...

What I want to do is have 2 pull down lists, for example a state pull
down list and a city pull down list. What I would like to have done is
when you select a state from the state pull down list then the city
pull down list will populate with all the cities from that selected
state. I know that is a lot of data but that is just an example. Or
something like when you are looking up cars online they have a make
pull down list and a model pull down list, and when you select the make
it will populate the model pull down list with all the models from that
make. Thank you.

Nov 25 '05 #1
2 3748
Nick wrote:
What I want to do is have 2 pull down lists, for example a state pull
down list and a city pull down list. What I would like to have done is
when you select a state from the state pull down list then the city
pull down list will populate with all the cities from that selected
state. I know that is a lot of data but that is just an example. Or
something like when you are looking up cars online they have a make
pull down list and a model pull down list, and when you select the make
it will populate the model pull down list with all the models from that
make. Thank you.


Hi Nick,

You basically have two options:

1. Use client-side javascript: load the data from both lists into
javascript arrays and write an onclick handler for the first selectbox,
to set the contents of the second selectbox.
You could check out
http://www.blueshoes.org/en/javascri...levelselector/
for example. You can use that component which works like I described.

2. Use AJAX to allow communication with the server when you click an
item in the first selectbox. You don't need to preload all data
client-side like that.
If you want to know more about this technique, read my tutorial at:
http://www.phpforums.nl/cgi-bin/foru...num=1131752404

HTH.

--
http://www.phpforums.nl
Nov 25 '05 #2
Following on from Peter van Schie's message. . .
You basically have two options:

Three!

A single list with all options in the form state,city (or city,state)
sorted on the first item. No JS or anything else required.
Four!

Of course PHP sends a whole page and then shuts down so isn't
interactive to the level you want . . .
.. . . But there *is* as way using what I call a flying screen:
The principle is that your page _opens a new window_ containing a form
filled with /the appropriate/ list which then returns the selection to
the session and closes itself.

In your particular case I wouldn't use it as the main window doesn't
update, but it can be handy if you have say a form with the possibility
of wanting to edit the details of some of the items in it. eg:

Team leader [Jim Smith v] [>details]

(drop down and button) where the button brings up details of Jim Smith
in a separate window, perhaps with the possibility of 'doing things',
This means that the main flow is not obscured.

or
Project [Cold Fusion v] [>projects]
where the button allows you to edit the list of projects, perhaps going
off into details about them in another window.

Finally it _is_ possible to get the value picked in a flying window back
to the main screen 'in real time'.
Project name : Cold Fusion [>Change]
where the Change button leads to a screen that allows you to maintain
and select a project, This requires clever javascript passing the
document elements between documents. On closing the flying screen the
form will now be updated to perhaps
Project name : Indian Rope Trick [>Change]

* The advantage of this technique is the flying window is just a side
branch to the main flow of the form which only needs to be used on
occasion but is there where you want it when you want it rather than
having to traipse round the system looking for a maintenance screen.

* The disadvantage is that it is rather hairy.

I've written an article on the subject and have packaged code but I
can't find the article at present and the code would need some hacking
to integrate with the way you write screens ('cos I have a weird home
grown method which is great for quick building but NBG for glueing to
non-weird code models.)

--
PETER FOX Not the same since the statuette business went bust
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Nov 26 '05 #3

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

Similar topics

1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
3
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
1
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down...
3
by: Sampson | last post by:
I have a question about enumeration and how to populate them during runtime. I am using vb.net but will happily take any advice in c# as well. Here is an example to help illustrate what I am...
7
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
0
by: guidopapinino | last post by:
What I want to do is have 2 pull down lists, for example a state pull down list and a city pull down list. What I would like to have done is when you select a state from the state pull down list...
1
by: SpankyTClown | last post by:
Hi, Problem: How do I create a form that contains a pull down list for the source and destination (reference the table definition shown below) that shows the name of the item not the id number?...
1
by: rajarameshvarma | last post by:
Hi, I have two user controls in an asp.net webpage each contains a DropDownList. Depending on the selection of the drop down in one user control i need to populate data in the other drop down...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.