This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 60082
    
  65

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]
 
wood burning stoves
 
subject: Populating the Drop-down Box using Ajax
 
Similar Threads
drop down List box in jsp
how jsf component get the value from backing bean instead of submitted value after validation error
select values for second drop down
Dropdown values for JSP
more once how can we submit JSP values to Action