• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating the Drop-down Box using Ajax

 
Jahnavi Kondapaneni
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic