Professional Web Applications Themes

Dynamic multiple dropdown population - MySQL

Greetings: I have a table with 3 pieces of data that I would like to use to dynamically populate 3 drop downs using javascript. The fields are state, orgname, office. If it's not already obvious, I'd like orgname drop down to change when a state is selected and I would like office drop down to change when an orgname is selected. I can do this with multiple tables but am having difficulty getting it to work when the data is in the same table. Below is the code to get state and orgname from separate tables(the code reflects one table ...

  1. #1

    Default Dynamic multiple dropdown population

    Greetings:

    I have a table with 3 pieces of data that I would like to use to
    dynamically populate 3 drop downs using javascript. The fields are
    state, orgname, office. If it's not already obvious, I'd like orgname
    drop down to change when a state is selected and I would like office
    drop down to change when an orgname is selected. I can do this with
    multiple tables but am having difficulty getting it to work when the
    data is in the same table. Below is the code to get state and orgname
    from separate tables(the code reflects one table and is broken in the
    below state). It's the best I can come up with and I can see why it
    doesn't work but I know there must be a way to pull all the pieces from
    a single table. Advice is much appreciated.

    <code>
    $list=$_SESSION['list'];
    if(isset($list) and strlen($list) > 0){
    $quer=mysql_query("SELECT DISTINCT orgname,org_id FROM organization
    WHERE state=$list ORDER BY orgname");
    }else{$quer=mysql_query("SELECT DISTINCT orgname FROM organization ORDER
    BY orgname"); }
    $quer2=mysql_query("SELECT DISTINCT state FROM organization ORDER BY
    state");

    //first drop down
    echo "<select name='state' onchange=\"reload(this.form)\"><option
    value='0'>Select one</option>";
    while($state = mysql_fetch_array($quer2)) {
    if($state['org_id']==$list){echo "<option selected
    value='$state[state]'>$state[state]</option>"."<BR>";}
    else{echo "<option value='$state[state]'>$state[state]</option>";}
    }
    echo "</select>";

    //next drop down
    echo "<select name='org'><option value=''>Select one</option>";
    while($org = mysql_fetch_array($quer)) {
    echo "<option value='$org[org_id]'>$org[orgname]</option>";
    }
    echo "</select>";
    </code>
    --

    Regards,

    Jeff Gardner
    ___________________________

    "Contrary to popular belief, Unix is user friendly. It just happens
    to be very selective about who its friends are." --Kyle Hearn
    Jeff Guest

  2. #2

    Default Re: Dynamic multiple dropdown population

    Jeff Gardner wrote: 

    Well, a couple of things. First of all, in your first dropdown you have

    if ($state['org_id']==$list ...

    What is $state['org_id']? Also, you should be checking to see if $list
    is not set before the comparison (all you're doing is hiding the error
    with the '').

    But what is the incorrect output (the generated code)? That would help
    a lot. To test the code here I'd have to build a sample database and
    try to run your code.

    Or better yet, to you have a url?

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

Similar Threads

  1. Dynamic form population
    By lmah in forum Macromedia ColdFusion
    Replies: 1
    Last Post: March 30th, 08:21 AM
  2. dynamic list population
    By wwsteeb in forum Dreamweaver AppDev
    Replies: 2
    Last Post: February 25th, 09:41 PM
  3. DYNAMIC Dropdown. How to stick on non dynamic choice?
    By Lesley G in forum Dreamweaver AppDev
    Replies: 3
    Last Post: February 23rd, 05:49 PM
  4. dropdown and dynamic text field
    By lukemack in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 19th, 12:07 AM
  5. Dynamic population of multidimensional array?
    By Kevin Torr in forum PHP Development
    Replies: 0
    Last Post: November 25th, 10:10 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139