title: Dynamically created checkboxes using ajax from sql result set
body: <p>I am looking to use ajax to dynamically create checkboxes each time you change your selection from a <code>&lt;select&gt;</code> tag, see the below screenshot for a section of the <strong>form</strong> that is relevant:</p>
  
  <p><a href="https://i.stack.imgur.com/EHVMk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EHVMk.png" alt="snippet"></a>
  </p>
  
  <p><strong>NOTE:</strong> The checkboxes under "<strong>Queues</strong>" should be dynamic.</p>
  
  <p>At the moment, when you change the value for <strong>Team</strong> it grabs the team name (in this case "Test"), then using ajax (POST) it returns the Manager name for that team.</p>
  
  <p>What I want it to do is look up another table that has a list of the "queues" associated with each team; I am going to add an "onchange" attribute in the tags for the "<strong>Manager Name</strong>" field.</p>
  
  <p>Below is the code I'm currently using to accomplish the <strong>Team</strong> => <strong>Manager Name</strong> dynamic filling:</p>
  
  <pre><code>&lt;script&gt;
          window.onload = function() {
              getManager($("#team").val());       
          }
  
          function getManager(team) {
              $.ajax({
                  type: "POST",
                  url: "getManager.php",
                  data: {team:team}
              }).done(function( manager ) {
                  $("#manager_name").val(manager);
              });
          }
  &lt;/script&gt;
  </code></pre>
  
  <p>And here is the <code>getManager.php</code> file that it uses:</p>
  
  <pre><code>&lt;?php
  
  require("../../database/db.php");
  
  $mysqli = new db("nab_reporting");
  
  if ($mysqli-&gt;connect_errno) {
      printf("Connect failed: %s\n", $mysqli-&gt;connect_error);
      exit();
  }
  
  $team=$mysqli-&gt;real_escape_string($_POST['team']);
  
  $result = $mysqli-&gt;query("SELECT manager_name FROM team WHERE teamname = '".$team."'");
  
  $row = $result-&gt;fetch_assoc();
  
  echo $row['manager_name'];
  
  mysqli_close($mysqli);
  
  ?&gt; 
  </code></pre>
  
  <p>Keeping in mind that the above works; I now need a way to use the <code>onchange</code> attribute of the <strong>Manager Name</strong> field that will use ajax (similar to above), passing another php page the value that is currently in the field (in this case Kane Charles) and will return a result set (array or JSON maybe?) containing a list of all queues in the database that match up with that Team name.</p>
  
  <p>Below is the html code for each of the different bits:</p>
  
  <p><strong>TEAM</strong></p>
  
  <pre><code>&lt;select name="team" id="team" required="required" onchange="getManager(this.value)"&gt;
                 &lt;?php 
                      include(__DIR__ . "/../../database/db.php");
                      $db = new db("nab_reporting");
                      $result = $db-&gt;query("SELECT teamname FROM team");
                      while ($row = $result-&gt;fetch_assoc()) {
                          echo "
                          &lt;option value=\"" . $row['teamname'] . "\"&gt;" . $row['teamname'] . "&lt;/option&gt;
                          ";
                      }
                      $db-&gt;close();
                   ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p><strong>MANAGER NAME</strong></p>
  
  <pre><code>&lt;input type="text" name="manager_name" id="manager_name" required="required" onchange="getQueues(this.value)"&gt;
  </code></pre>
  
  <p><strong>QUEUES</strong></p>
  
  <pre><code>&lt;label&gt;
      Queues
  &lt;/label&gt;
  &lt;div id="queue_options"&gt;
      &lt;!-- queues dynamically created here --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I need the contents of <strong><code>queue-options</code></strong> to be erased and reset to only the queues associated with the current team; I haven't done a great deal with ajax, hence why I'm posting on here.</p>