| Author |
content of dropdown B will depend on what is selected on dropdown A
|
sarika Gupta
Greenhorn
Joined: Apr 27, 2005
Posts: 18
|
|
hey guys, i want to know how to do this in JSP.. Say I have dropdown A: <select name = "department"> <option>A</option> <option>B</option> <option>C</option> </select> now depending on what was selected in drodpownA, drodown B will have the following options, if "A" was selected, values 1, 2, and 3 will be the options if "B" was selected, values 4, 5, and 6.. and if "C" was selected, values 7,8,9. Now, these values (1-9) will be loaded from the database. and I just want to have a single page for the two dropdowns, how would that be possible? Could you write me the code?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Could you write me the code?
No. That's not in the spirit of these forums; people prefer you learn what you need to do and apply that knowledge to do it yourself, rather than blindly copying from someone else. We will however be happy to help you solve any problems you run into doing this. The steps you need are probably something like this: You will need some clientside JavaScript to respond to an event on drop down A. <select /> form elements have a bunch of events - I can't remember off the top of my head what they are (you are better asking in the HTML and JavaScript forum, or reading some documentation - MSDN has a useful list, be aware though that some of these might be IE only).You will either need a round trip to the server to retrieve the values for your second drop down form the database, or you will need build the second drop down in clientside script if you don't want a round trip (again, the HTML and JavaScript forum is going to be more help there).
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Search this forum with "select list" as the search criteria. You'll find a lot of post on this subject -- some with code examples.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Kedar Dravid
Ranch Hand
Joined: May 28, 2004
Posts: 333
|
|
|
I was faced with a similar situation some time back. After some search on Google and Javaranch and going through some of the suggested solutions, I felt the best (and easiest) solution to this is to use IFRAMEs to load a class which calls the method to retieve the corresponding values. This also helps performance-wise, BTW.
|
 |
Rahul Juneja
Ranch Hand
Joined: Aug 03, 2002
Posts: 425
|
|
Sarika, Are you done with this code, or you are still looking for the code ? Cheers, Rahul
|
Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
|
 |
 |
|
|
subject: content of dropdown B will depend on what is selected on dropdown A
|
|
|