Google Blogoscoped

Forum

Populate a second drop down list upon selection value of first drop down list

Suresh S [PersonRank 10]

Thursday, June 11, 2009
10 years ago3,569 views

Hi Guys,

A very simple problem in jsp. i want to populate a second drop down list upon selection value of first drop down list . how can i do this in jsp.upon the selection of value from first drop down the parameter will be passed to a sql query that takes this parameter and the resulting rows will be populated in second drop down. what is the mature logic to do this without using ajax.

Tony Ruscoe [PersonRank 10]

10 years ago #

I'd do this client-side using JavaScript by loading all the possible values into a set of arrays or name/value pairs. Then stick an onchange event on the first drop down to repopulate the second drop down.

Of course, you don't want to rely on Javascript firing, so you should check your submission server-side too to make sure it validates. If the value isn't valid, you'll have reloaded the page by that time, so you can repopulate the second drop down using the query server side based on the submitted value for the first drop down.

Suresh S [PersonRank 10]

10 years ago #

Hi Tony,

Thanks for the logic, I thought of doing with two forms elements and storing the state in hidden fields.

This thread is locked as it's old... but you can create a new thread in the forum. 

Forum home

Advertisement

 
Blog  |  Forum     more >> Archive | Feed | Google's blogs | About
Advertisement

 

This site unofficially covers Google™ and more with some rights reserved. Join our forum!