browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need JavaScript / Ajax / DHTML help?

Get answers from our community of JavaScript / Ajax / DHTML experts on BYTES! It's free.

Through AJAX populate drop down

Newbie
 
Join Date: Sep 2006
Posts: 8
#1: Nov 8 '06
I need three drop down states,country,cities. States will populate from db then on the selection of state ..the list of coutries will populate and when select a country .its cities list will populate.
if some one can help out me please give me an example



ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Nov 8 '06

re: Through AJAX populate drop down


You can accomplish this via pure PHP by submitting the form each time you have selected a drop-down value. That is not very nice and a bit of a hassle processing your form.

A much better solution is to use JavaScript and, better still, use Ajax. That way you can populate the boxes via an asynchronous call from the client to the server (php) program without refreshing your page or forcing the user to hit a 'submit' each time.

For Ajax, there is a demo (and the solution's code) at website dhtmlgoodies.com at page 'Ajax samples', which can be reached via link Chained select boxes

Good luck.

Ronald :cool:
Newbie
 
Join Date: Sep 2006
Posts: 8
#3: Nov 8 '06

re: Through AJAX populate drop down


yes i am doing it through ajax .. but now i have problem that onchange of sec drop down i didn't get third dropdown .it populate all the values. i want to populate the cities of the selected country .
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Nov 8 '06

re: Through AJAX populate drop down


Not automatically with the sample I suggested.
You'll have to write a JavaScript function like the "getCityList(this)" for the extra catcher. And at the server side expand the code. So you'll have to have one catcher for for the count(r)y and one for the cities and a PHP (or other server) script that can handle both requests.

But 3 drop[-down lists are not in the sample, just 2 and that's why it is just a sample. You have to write that yourself. That can't be too difficult because you have a perfect example.

Ronald :cool:
Reply