SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ajax chained select menu with database driven

    hi, i'm quite new with ajax...
    thinking to make 2 select menus where the 1st select menu is for main category and the 2nd select menu shows the sub category of the main category...

    i found many tutorials over the internet, however, all of them do not use the connection to database in getting the item in 2nd select menu... (eg.http://bonrouge.com/~chain_select_ajax#end )

    I'm not sure how to pass the extracted data into the 2nd select menu...

    can anyone please advice ???

    thank you!

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If I understand you, you want menu 2 to be dependent upon the choice made in menu 1. You want to use ajax to do that.

    Isnt this like the airline websites, where you pick an airport to fly from and by magic the next box contains only those airports that they fly to, from the first pickbox choice?

    If so, you dont need ajax to do that. Look at how Ryanair and easyjet do it, its all JS arrays - why go back to the server at all?

    Now, if you have hundreds or thousands or options, then this might not work and in which case, ajax would be a good idea.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    yup, i need to go back to server because there are too many <option></option> to be included for each category....

    does anyone has any idea???

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i wonder how to extract the data from database in the below format:

    <?php
    function doIt($country) {
    switch ($country) {
    case "United Kingdom":
    return array('London','Manchester','Birmingham','Liverpool','Edinburgh','Cardiff','Belfast');
    break;
    case "United States":
    return array('Washington DC','New York','Los Angeles', 'Chicago');
    break;
    case "Australia":
    return array('Canberra','Melbourne','Sydney', 'Brisbane');
    break;
    case "Japan":
    return array('Tokyo','Osaka','Fukuoka','Sendai','Sapporo');
    break;
    }
    }

    $country=@$_GET['country'];
    $cities=doIt($country);
    foreach ($cities as $city) {
    echo '|'.$city;
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •