title: CodeIgniter : dependent dropdown not working
body: <p><strong>my controller :-</strong></p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Cnewincident extends CI_Controller
  {       
      public function __construct()
      {
          parent::__construct();        
          $this-&gt;load-&gt;database();
      }
      public function index()
      {            
          $this-&gt;load-&gt;model('users/supervisor/Mnewincident');
          $data['category'] = $this-&gt;Mnewincident-&gt;getCatgories();  
          //loads up the view with the query results  
          $this-&gt;load-&gt;view('users/supervisor/vnewincident',$data);
  
          if($this-&gt;input-&gt;post('addrequest'))
          {                
              $this-&gt;load-&gt;model('users/supervisor/Mnewincident');
              // to get the username from table who is creating  this request
              $session_data = $this-&gt;session-&gt;userdata('emailid');
              $firstname =  $this-&gt;Mnewincident-&gt;get_firstname($session_data);
  
              // passing that usename in newincident table
              if($this-&gt;Mnewincident-&gt;add_request($firstname))
              {
                  $this-&gt;session-&gt;set_flashdata( 'message', 'Request added successfully.' );
                  redirect('users/supervisor/Cnewincident');
              }
              else
              {
                  $this-&gt;session-&gt;set_flashdata( 'message', 'Failed to add the request. Try again' );
                  redirect('users/supervisor/Cnewincident');
              }
          }
      }
      //call to fill the second dropdown with the subcategories
          public function loadsubcat()  
          {  
             echo $category_id = $this-&gt;input-&gt;post('id',TRUE);
             $subcatData['subcatDrop']=$this-&gt;Mnewincident-&gt;getSubcatgories($category_id);  
             $output = null;  
             foreach ($subcatData['subcatDrop'] as $row)  
             {  
                $output .= "&lt;option value='".$row-&gt;subcategory_description."'&gt;".$row-&gt;subcategory_description."&lt;/option&gt;";  
             }  
             echo $output;  
          } 
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>My model :-</strong>                                                            </p>
  
  <pre><code> class Mnewincident extends CI_Model
   {
       public function __construct()
      {
          $this-&gt;load-&gt;database();
      }
  
         public function getCatgories()  
         {  
            $this-&gt;db-&gt;select('category_id,category_description');  
            $this-&gt;db-&gt;from('tbl_categorymaster');  
            $query = $this-&gt;db-&gt;get();
            foreach($query-&gt;result_array() as $row)
            {  
               $data[$row['category_id']]=$row['category_description'];  
            }
            return $data;  
         }  
  
         public function getSubcatgories($category_id=string)  
         {  
            $this-&gt;db-&gt;select('srno,subcategory_description');  
            $this-&gt;db-&gt;from('tbl_subcategorymaster');  
            $this-&gt;db-&gt;where('category_id',$category_id);  
            $query = $this-&gt;db-&gt;get();  
            return $query-&gt;result();  
         } 
  }
  </code></pre>
  
  <p>My view code :-</p>
  
  <pre><code>              $(document).ready(function() {  
                   $("#category").change(function(){                       
                   $.ajax({  
                      url:"&lt;?php echo base_url()."users/supervisor/Cnewincident/loadsubcat"?&gt;",  
                      data: {id:$(this).val()},  
                      type: "POST",  
                      success:function(data){  
                      $("#subcategory").html(data);  
                   }  
                });  
             });  
          });  
  </code></pre>
  
  <p></p>