Skip to Content
avatar image
Former Member

dropdownbox Selection in jsp

hi everybody,

In jsp i have 3 drop down boxes are there (say country, state , district )

if i select country means , that coressponding states should populate in that

State dropdown box. , in the same way if i select state means that

corresponding districts must populate in the District drop down box....

so plese send me the ......


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jun 23, 2007 at 07:56 AM


    Use the onChange attribute of the tag for drop down call a javascript function

    which will go to controller with value of the selected country as parameter to access the database with a where clause to populate the drop down box for state.

    eg :


    function loadState(country){

    var country = // get the country name

    pass the country name to the controller or bean where database access is performed.




    <SELECT NAME="Country" onChange="loadState(this)">

    <OPTION value="INDIA">India </OPTION>

    <OPTION value="USA">United States </OPTION>

    <OPTION value="AUSTRALIA">Australia </OPTION>


    I think this example will help you.



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Tony

      In your case you have to use AJAX.

      Why AJAX i am explaining you. When you are selecting a country name then corp. State name will come from database so you need execute a jsp or servlet in server. So if you don't use AJAX then it whole page will submitted and refreshed. But if you use AJAX then without submitting the page you are getting the corp. list of State. It is also same case at the time when you are selecting a state to get district. Finally you will also submit the page. So in a single page you are submitting 3 times. To prevent that you can use AJAX.

      To learn ajax go through this link.