Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

content of dropdown B will depend on what is selected on dropdown A

 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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).

  •  
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Search this forum with "select list" as the search criteria.
    You'll find a lot of post on this subject -- some with code examples.
     
    Kedar Dravid
    Ranch Hand
    Posts: 333
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 425
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sarika,

    Are you done with this code, or you are still looking for the code ?

    Cheers,
    Rahul
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic