tags:

views:

474

answers:

1

Hi,

I have two dropdowns in my form. The first one Queries for a set of data and displays them. Based on the value selected in the first dropdown i have to query the database, using that selected value as a parameter and populate the second dropdown. In short, based on the first dropdown, second one has to be populated dynamically. Am coding in JSP. Please do help on this!

Thanks, Geetha

+1  A: 

You can do this in 3 ways:

  1. Submit the form to the server side and let the JSP/Servlet load and display the child dropdown accordingly based on the request parameter. Technically the simplest way, but also the least user friendly way. You probably also want to revive all other input values of the form.

  2. Let JSP populate the values in a JavaScript array and use a JavaScript function to load and display the child dropdown. A little bit trickier, certainly if you don't know JavaScript yet, but this is more user friendly. Only caveat is that this is bandwidth and memory inefficient when you have relatively a lot of dropdown items.

  3. Let JavaScript fire an asynchronous HTTP request to the server side and display the child dropdown accordingly. Combines the best of options 1 and 2. Efficient and user friendly.

I've posted an extended answer with code samples here: Populating child dropdownlists in JSP/Servlet.

BalusC
Used the second option of the solution..Thank you! :)
Geethapriya.VC
You're welcome.
BalusC