aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Populating the Drop-down Box using Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Populating the Drop-down Box using Ajax" Watch "Populating the Drop-down Box using Ajax" New topic
Author

Populating the Drop-down Box using Ajax

Jahnavi Kondapaneni
Ranch Hand

Joined: Jan 25, 2008
Posts: 56
Hi all,

I am having a dropdown list box which displays the different states like "Andhra Pradesh","Karnataka"...etc.
On selection of one of the states I need to populate another drop-down box with the list of cities that come under that state.
Now I know that I can call a function onchange and create xmlHttp object and send the request along with the parameters.
Like <select name="state" onchange="validate()">
My question is how do I display another dropdown box with the values of cities in it once the state is selected.
Hope I made my question clear....
Jahnavi Kondapaneni
Ranch Hand

Joined: Jan 25, 2008
Posts: 56
Since I want to populate the drop down list box.
The response will be in form of an array.
How do I handle the response which is of the form Array
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

You'd iterate through the array and create option elements for each, adding them to the select element. The API for the select element is straight-forward.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Populating the Drop-down Box using Ajax