How can I do this using Ajax?
Main Topics
Browse All TopicsThe effect I want to create is really simple, however, doing it is not, at least for me.
I have a form on a page. When a selection in combo box 1 is made it populates combo box number 2 then 3 then 4.
Like this...
Box 1 - Country
Box 2 - State
Box 3 - City
Box 4 - Zip Code
So for this example let assume I make the following choices:
Box 1: United States (All countries would be displayed in Box 1)
Box 2: Idaho (All 50 US States would have been available
Box 3: Boise (A list of cities that I wanted for Idaho would be here)
Box 4: 83705 (a List of available zip codes for Boise, ID, USA)
I know I have to supply the lists for each box, that is easy, I have the data.
#1. How can I do this?
#2. Is it possible to do this via a connection to a DB where each table in the DB contains information for a different field? That would be the best but I'll take whatever I can get help with.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here is a how-to i found that goes through and explains all of the necessary code:
http://www.webmonkey.com/t
And here is a working example of said code: http://duvinci.com/project
Note that his script is fairly bare-bones, and pulls data from a flat text file, rather than a database. It should be fairly trivial to use PHP to connect to your database rather than pull data from a text file.
Business Accounts
Answer for Membership
by: bradl3yPosted on 2009-04-15 at 12:33:39ID: 24151735
This could all be done without much javascript if you don't mind reloading the page after each selection. Set the onchange attribute of the select element to submit the form. Submitting the form.
The page would load, write php to generate a second selection box based on what was submitted for the first.
If you want to do this without reloading, you would need to use an AJAX solution. Onchange of the select element, send the value to the server, have the server generate the code (using PHP if you wish) for the second drop down box that will be returned to the page via AJAX, and use javascript to replace the second drop down list with the new list.