Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Dynamic load selectboxes help

    Hi,

    I'm having a problem o coding a feature that would enable to dynamically load selectboxes using PHP and Javascript.

    My problem is on Javascript and not on PHP.

    Thanks in advance for any help.

    MarioPro

    Here's what I would like to do:

    <!--### The Data ###-->
    Populate selectboxes dynamically for the following information, which is directly related in my database with ID's.
    HTML
    1st. Selectbox: County
    2nd. Selectbox: City
    3rd. Selectbox: Location

    PHP/MySQL
    $county_ID (Table counties)
    $county (Table counties)
    $city_ID (Table cities)
    $city (Table cities)
    $location_ID (Table locations)
    $location (Table locations)

    <!--### The Objective Explained ###-->
    Once the user selects the County, the City and Location selectboxes would be populated with the data corresponding to the County selected, without reloading the page.

    <!--### The Main SelectBox Schema ###-->

    Select your county:
    <SELECT NAME="cnt[county]">
    <OPTION VALUE="Any">Any</OPTION>
    <?
    // Selects the county and populates it even
    // if the table is updated
    $query = "SELECT * FROM counties";
    $result = mysql_query($query);
    while($rowCnt = mysql_fetch_array($result)){
    echo '<OPTION VALUE="'.$rowCnt['ID'].'" ';
    // Set the selected county from the earlier search if any
    if($rowCnt['ID'] == $cnt['county']){
    echo ' SELECTED ';
    }
    echo '>'.$rowCnt['county'].'</OPTION>'."\n";
    }
    ?>
    </SELECT>

    Select your City:
    <SELECT NAME="c[city]">
    <OPTION VALUE="Any">Any</OPTION>
    <?
    // Selects the city and populates it even
    // if the table is updated
    $query = "SELECT * FROM cities WHERE county_ID='".$f['county']."'";
    $result = mysql_query($query);
    while($rowC = mysql_fetch_array($result)){
    echo '<OPTION VALUE="'.$rowC['ID'].'" ';
    // Set the selected city from the earlier search if any
    if($rowC['ID'] == $c['city']){
    echo ' SELECTED ';
    }
    echo '>'.$rowC['city'].'</OPTION>'."\n";
    }
    ?>
    </SELECT>

    Select your City:
    <SELECT NAME="l[location]">
    <OPTION VALUE="Any">Any</OPTION>
    <?
    // Selects the location and populates it even
    // if the table is updated
    $query = "SELECT * FROM locations WHERE city_ID='".$f['city']."'";
    $result = mysql_query($query);
    while($rowL = mysql_fetch_array($result)){
    echo '<OPTION VALUE="'.$rowL['ID'].'" ';
    // Set the selected location from the earlier search if any
    if($rowL['ID'] == $l['location']){
    echo ' SELECTED ';
    }
    echo '>'.$rowL['location'].'</OPTION>'."\n";
    }
    ?>
    </SELECT>
    Last edited by MarioPro; 07-27-2002 at 08:11 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    http://javascriptkit.com/cutpastejava.shtml

    look at double combo scripts

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for the tip. This might be useful for small arrays. Now imagine that one of mine - $cities, I have 308 names, joining with about 23 counties and 11 locations, this would become and enormous load on the page, eve if called as a js include.

    My objective was to populate the selectboxes with only the correspondent data, which would result on smaller arrays for the combos.

    Any way thanks for the valuable help.

    MarioPro

  • #4
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Has anyone seen this type of combo or selectboxes functioning with Javascript + PHP?

    Thanks in advance for any help.

    MarioPro

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the tip. This might be useful for small arrays. Now imagine that one of mine - $cities, I have 308 names, joining with about 23 counties and 11 locations, this would become and enormous load on the page, eve if called as a js include.
    Not as much as you might think. The overall "work" the page has to do might be significant- this one piece won't be overly slow I strongly suspect.


    BUT if it worries you, I suggest you do it from another window - that's what I did. I have a dynamic list, and to add/delete from it I have a button that opens another window and the list is passed to that window and edited from there. Click on "finish" and it's passed back to the parent window.

    This technique eliminates the overhead you're worried about from the parent page and it's only invoked when the user asks for it (clicks on the button).

  • #6
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Once again, thanks for your reply.

    Your suggestion of oppening another window seems to be very handful, and user friendly as well.

    Do you have any link where I may see some code of that? I'm not as good (in fact a newbbie) on Javascript as in PHP/MySQL.

    Thanks!


    MarioPro


  •  

    Posting Permissions

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