• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).

  •  
    Sheriff
    Posts: 13411
    Firefox Browser VI Editor Redhat
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Ranch Hand
    Posts: 333
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Ranch Hand
    Posts: 425
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sarika,

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

    Cheers,
    Rahul
     
    Can't .... do .... plaid .... So I did this tiny ad instead:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic