on 06-21-2007 8:05 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Ritu,
Ok fine...
If i select India means that corresponding data comes from database
how to populate that data into the State dropdrown box..
ok , i got those values in some array....how i place those values
in the <option> tag......
can i place any for loop inside the Select Tag....if yes,
means plz send me....
<SELECT NAME="State" >
<OPTION >Select </OPTION>
</SELECT>
Hi,
If it is a simple jsp then put the options tag in the while(rs.next) loop.
e.g :
while(rs.next){
<option>rs.getString("State");</options>
}
Or else...put in the arraylist and use a loop to that of the size of the arraylist.
e.g
for(int i = 0; i<= arr.size; i++ ){
<option>arr.get(i)</options>
}
If you use any of the two options it will work.
Thanks
Ritu
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.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.