title: Populate Dropdown based on another Dropdown Using Ajax, jQuery and Codeigniter
body: <p>I just wanna ask how to populate a dropdown based on another dropdown's value.</p>
  
  <p>When I select a Campaign, it will show the names of the people that are in that Campaign in another dropdown but the value must be the id of the name.</p>
  
  <p>Here is my Model</p>
  
  <pre><code>function get_agents($campaign_id)
  {
      $campaign_id1 = mysqli_real_escape_string($this-&gt;db-&gt;conn_id,trim($campaign_id));
      $query = $this-&gt;db-&gt;query("SELECT tbl_employee.emp_id, CONCAT(tbl_applicant.fname, ' ', tbl_applicant.lname) AS fullname FROM tbl_applicant INNER JOIN tbl_employee ON tbl_employee.apid=tbl_applicant.apid INNER JOIN tbl_account ON tbl_employee.acc_id=tbl_account.acc_id WHERE tbl_account.acc_id='".$campaign_id1."'");
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>Here is my Controller</p>
  
  <pre><code>public function getAgents()
  {
     $campaign_id = $this-&gt;input-&gt;post('campaign_id');
     $this-&gt;KudosModel-&gt;get_agents($campaign_id);
     echo $result;
  }
  </code></pre>
  
  <p>Here is my AJAX</p>
  
  <pre><code>$('#addCampaign').on('change', function(){
          $.ajax({
              type : 'POST',
              data : 'campaign_id='+ $('#addCampaign').val(),
              url : 'controller/method',
              success : function(data){
                  $('#anyname').val(data);
              }
          });
      }); //I dont know what to do here
  </code></pre>
  
  <p>Thanks in advance guys!</p>