How to populate multiple dependent dropdown in jsp
Does anyone know how to use a database to dynamically populate a series of
menus in a form that resides in a single JSP (no frames please)?
For example, I have 3 drop-down menus in the same form named A, B and C.
Based on what the user selects in menu A, I want to query the database and
present a set of options related to A in menu B. Based on what the user
selects in menu B, I want to query the database and present a set of options
related to B in menu C. Finally, when A, B and C are all selected, the user
would submit the form for processing. How can this be achieved without subjecting
the server/network to excessive overhead?
Please reply it to alok.singh@patni.com
Message was edited by:
SinghAlok
[783 byte] By [
SinghAloka] at [2007-10-3 10:14:05]

This question is asked tons of times. There is code available on this site and on google.
Here are a couple of suggestions:
There are two ways to do this
1) All javascript: When the page is first made, you retrieve all possible values for the second select and store them in a javascript array of arrays. Then, on change event of first select, choose which options to put in the second option. This is most usefull when the total number of values is small.
2) Server round trip: Use the onChange event from the first select to call a js function that submits the form to someplace that determines which values to add to the second select, then re-display the jsp with the new values...
3) Shorter Server round trip: Like 2) but instead of submitting the form, use the XMLHttpRequest object in JavaScript to communicate the selected option to the server and get a response with what to fill in the next select box with.
If you go to "Auto" section in MSN or Yahoo, it populates the Model based on Make without refresh. They should use javascript I think.
http://autos.yahoo.com/used_cars.html;_ylt=AteU0hYwB9CSN6xaCanNT.EEc78F
search online, you will get code. You can use AJAX technik to get the data that will not refresh the page.