By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,972 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,972 IT Pros & Developers. It's quick & easy.

Automatically populate a pull down list...

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.