File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Drop Downs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Drop Downs" Watch "Drop Downs" New topic

Drop Downs

Chinni Bujji
Ranch Hand

Joined: Jan 31, 2007
Posts: 60

I have 2 drop down in the jsp page.
The first drop down is dynamically populated

The second drop down will be populated depending on the selection in the first one.

The second drop down title should be Select XXX Type where XXX is the value selected in the first drop down
I am having the id of the first selected drop down and i am sending the id to the Action Class

How would i get the value of that particular id ?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

This one of our most asked question.
Search this, and the HTML forum (Google too) with keywords:
"Dependent dropdown" or "cascading dropdown" and you will find plenty of discussion on the subject.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
sudha swami
Ranch Hand

Joined: Apr 24, 2007
Posts: 186
Did you find any code related to it. If so, could you please pass the url/ code which would be helpful.
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
Does this help or you are looking for a struts specific solution ?
Remove - from ev-al

SCJP 1.4
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Why the uncessessary use of eval()?

Also this example does not account for the fact that the values in the secondary dropdown depend upon the selected value.
[ October 12, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
True eval is unnecessary ..
Here is a better example

sudha swami
Ranch Hand

Joined: Apr 24, 2007
Posts: 186
[Edit: thread hijack removed]
[ October 16, 2007: Message edited by: Bear Bibeault ]
Gayathri Chowduru
Ranch Hand

Joined: Oct 17, 2007
Posts: 42
So, your first drop down is being populated by a server call. right. In the Select tag, give the javascript function, like
<Select name="firstDropDown" onChange="displaySecondDropDownList()">
<option ..></option>
in the javascript function,
function displaySeconDropDownList(){
var selectedValue = document.forms[0].firstDropDown.options[selectedIndex].value
then take a hidden variable and assign this value to that variable and set in the corresponding form.
Then invoke the action class, and get the corresponding second dropdown list values from the database based on this selected value. :-)
shah rhukh

Joined: Oct 08, 2007
Posts: 9

i had face the same problem recently........
For this AJAX is the best solution..
I agree. Here's the link:
subject: Drop Downs
jQuery in Action, 3rd edition