Multiple selects - how can I populate more than just the first one.

Multiple selects - how can I populate more than just the first one.

Hi jQ,

I have a form that generates 'n' amount of related select boxes.  Some records will have one set of related select boxes where others will have ten sets. I'm struggling with a technique in which I can get each of the children select boxes populated based on the value of it's parent.

Currently I'm only able to find the very next select box and get it populated (by class I believe), but when I go down to the next set of select boxes, the change function is still only reading the value from the first select box.

The selelct boxes are id "acdsel-0, acd2sel-0 (first set)
acdsel-1, acd2sel-1 (second set) and so on...
class = acdsel and acd2sel
name = acdsel[] and acd2sel[]

If these only appeared once I would have it worked out, how can I get each set of selects to act independent of any previous ones?

I thought I could get it working by using
  1.  var select = closest('td').next().find('select');
But that didn't work out, perhaps I don't have it in the correct place?
Here's the code I'm using to generate the select boxes.
The populate function is looking for a class 'acdsel' which I don't think is going to work.
  1. <?php
    <script type="text/javascript">
    $(document).ready(function() {
            populateACD();
            $(".acdsel").change(function() {
                    populateACD();
            });

    });

    function populateACD() {
            $.getJSON('/acd/acd2json.php', {acdSelect:$(".acdsel").val()},
    function(data) {
    //        var select = closest('td').next().find('select');
            var select = $(".acd2sel");
                    var options = select.attr('options');
                    $('option', select).remove();
                    $.each(data, function(index, array) {
                      options[options.length] = new Option(array['ACD2'], array['ACD2ID']);
                    });
            });
    }
    </script>
    </head>
    <body>
    <div class="topGraphic">  
    <?php
    echo "<td><select name=\"acdSelect[]\" id=\"acdsel-".$key."\" class=\"acdsel\">
    <option value=\"0\">ACD1&nbsp;&raquo;</option>";
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    $squery = "SELECT ACD1ID, ACD1 from ACD1";
    $sdata = mysqli_query($dbc, $squery);
      // Loop through the array of ACD1s, placing them into an option of a select
    while ($row = mysqli_fetch_array($sdata)) {
    echo "<option value=" . $row['ACD1ID'] . ">" . $row['ACD1'] . "</option>\n";
        echo "</select>";
        echo "</td>";
        }

    if ($row['ACD2'] == NULL)






































  2. {
    echo "<td>";
    echo "<select name=\"acd2Select[]\" id=\"acd2sel-".$key."\" class=\"acd2sel\">
    <option>ACD2&nbsp;&raquo;</option></select>";
    echo "</td>";
    $key++;
                        }








Thank you jQ, hope your Monday is a good one~!

-aaron