Through AJAX populate drop down

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rubinamunir
    New Member
    • Sep 2006
    • 8

    Through AJAX populate drop down

    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
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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.co m at page 'Ajax samples', which can be reached via link Chained select boxes

    Good luck.

    Ronald :cool:

    Comment

    • rubinamunir
      New Member
      • Sep 2006
      • 8

      #3
      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 .

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Not automatically with the sample I suggested.
        You'll have to write a JavaScript function like the "getCityList(th is)" 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:

        Comment

        Working...