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

thanks

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

    HI,

    Use the onChange attribute of the tag for drop down box.to 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 :

    <script>

    function loadState(country){

    var country = // get the country name

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

    document.forms.submit();

    }

    </script>

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

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

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

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

    </SELECT>

    I think this example will help you.

    Thanks

    Ritu

    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.

      http://www.w3schools.com/ajax/default.asp