title: how to filter data with dropdown in codeigniter
body: <p>I am developing an admin side right now and creating forms using template filter to call template and call page contain in template </p>
  
  <p>now i am stuck at drop down filter and my jquery doesn't calling my controller function </p>
  
  <p>i am not sure is it because of template or i am wrong at some code</p>
  
  <p><strong>Matchcon Controller</strong></p>
  
  <pre><code>public function matchscrbatcon()
      {
          $data['player']=    $this-&gt;Matchmodel-&gt;getAllPlayer();
          $data['team']=  $this-&gt;Matchmodel-&gt;getAllTeam();
          $data['match']= $this-&gt;Matchmodel-&gt;getAllmatch();
          $data['page'] = 'match/matchscrbat';
          $this-&gt;load-&gt;view('templates/form_template', $data);
          if($this-&gt;input-&gt;post('save'))
          {
              $insmsbdata=array('msbat_id'=&gt;'',
            'match_id'=&gt;$this-&gt;input-&gt;post('minfmname'),
              'team_id'=&gt;$this-&gt;input-&gt;post('mteamid'),
              'player_id'=&gt;$this-&gt;input-&gt;post('msbplayerid'),
              'inning_1or2'=&gt;$this-&gt;input-&gt;post('msbing'),
              'run'=&gt;$this-&gt;input-&gt;post('msbrun'),
              'ball'=&gt;$this-&gt;input-&gt;post('msbball'),
              'strike_rate'=&gt;$this-&gt;input-&gt;post('msbsr'),
              'four'=&gt;$this-&gt;input-&gt;post('msb4'),
              'six'=&gt;$this-&gt;input-&gt;post('msb6'),
              'wicket_by'=&gt;$this-&gt;input-&gt;post('msbwb'),
              'caught_by'=&gt;$this-&gt;input-&gt;post('msbcb'),
              'stumped_by'=&gt;$this-&gt;input-&gt;post('msbsb'),
              'runout_direct'=&gt;$this-&gt;input-&gt;post('msbrodb'),
              'runout1'=&gt;$this-&gt;input-&gt;post('msbro1'),
              'runout2'=&gt;$this-&gt;input-&gt;post('msbro2'));
              $this-&gt;Matchmodel-&gt;savemsbrecords($insmsbdata);
              echo '&lt;script&gt;alert("You Have Successfully updated this Record!");&lt;/script&gt;';
          }
      }
      function getteambymatch($matchid)
      {
          header('Content-Type: application/x-json; charset=utf-8');
                  echo(json_encode($this-&gt;Matchmodel-&gt;getAllplayingteam($matchid)));
      }
  </code></pre>
  
  <p><strong>matchmodel my model</strong></p>
  
  <pre><code> function savemsbrecords($insmsbdata)
        {
          $this-&gt;db-&gt;insert('matchscore_bat',$insmsbdata);
        }
      function getAllSeries()
        {
          $query=$this-&gt;db-&gt;query('SELECT series_id, series_name FROM series');
          return $query-&gt;result();
        }
        function getAllPlayer()
        {
          $query=$this-&gt;db-&gt;query('SELECT player_id, player_name FROM player');
          return $query-&gt;result();
        }
        function getAllTeam()
        {
          $query=$this-&gt;db-&gt;query('SELECT team_id, team_name FROM team');
          return $query-&gt;result();
        }
        function getAllVenue()
        {
          $query=$this-&gt;db-&gt;query('SELECT venue_id, venue_name FROM venue');
          return $query-&gt;result();
        }
        function getAllmatch()
        {
          $this-&gt;db-&gt;select("match_id, match_name, mdate");
          $this-&gt;db-&gt;from('match');
          $query=$this-&gt;db-&gt;get();
          return $query-&gt;result();
        }
       function getAllplayingteam($matchid)
        {
          $this-&gt;db-&gt;select("team.team_id, team.team_name,match.match_id");
          $this-&gt;db-&gt;from('team');
          $this-&gt;db-&gt;join('match','match.team1=team.team_id OR match.team2=team.team_id');
          $this-&gt;db-&gt;where('match.match_id',$matchid);
          $query=$this-&gt;db-&gt;get();
          return $query-&gt;result();
        }
  </code></pre>
  
  <p><strong>matchscrbat view file</strong></p>
  
  <pre><code>&lt;section class="content"&gt;
        &lt;div class="row"&gt;
            &lt;!-- general form elements --&gt;
            &lt;div class="box box-warning"&gt;
              &lt;div class="box-header with-border"&gt;
                &lt;h3 class="box-title"&gt;Player Details&lt;/h3&gt;
              &lt;/div&gt;
              &lt;!-- /.box-header --&gt;
              &lt;div class="box-body"&gt;
                &lt;form method="post" role="form"&gt;
                  &lt;!-- text input --&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Match&lt;/label&gt;
                    &lt;select class="form-control select2" name="minfmname" style="width: 100%;"&gt;
                      &lt;?php
                      foreach ($match as $key =&gt;$value) {
                        echo '&lt;option value="'.$value-&gt;match_id.'"&gt;'.$value-&gt;match_name.' date:'.$row-&gt;mdate.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Team&lt;/label&gt;
                    &lt;select class="form-control select2" name="mteamid" style="width: 100%;"&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Player&lt;/label&gt;
                    &lt;select class="form-control select2" name="msbplayerid" style="width: 100%;"&gt;
                      &lt;option selected="selected"&gt;&lt;/option&gt;
                      &lt;?php
                      foreach ($player as $row) {
                        echo '&lt;option value="'.$row-&gt;player_id.'"&gt;'.$row-&gt;player_name.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Inning 1 or 2&lt;/label&gt;
                    &lt;input type="text" name="msbing" class="form-control" placeholder="Enter..."&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Run&lt;/label&gt;
                    &lt;input type="text" name="msbrun" class="form-control" placeholder="Enter ..."&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Ball&lt;/label&gt;
                    &lt;input type="text" name="msbball" class="form-control" placeholder="Enter ..."&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Strike Rate&lt;/label&gt;
                    &lt;input type="text" name="msbsr" class="form-control" placeholder="Enter..."&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Four&lt;/label&gt;
                    &lt;input type="text" name="msb4" class="form-control" placeholder="Enter..."&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Six&lt;/label&gt;
                    &lt;input type="text" name="msb6" class="form-control" placeholder="Enter..."&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Wicket By&lt;/label&gt;
                    &lt;select class="form-control select2" name="msbwb" style="width: 100%;"&gt;
                      &lt;option selected="selected"&gt;&lt;/option&gt;
                      &lt;?php
                      foreach ($player as $row) {
                        echo '&lt;option value="'.$row-&gt;player_id.'"&gt;'.$row-&gt;player_name.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Caught By&lt;/label&gt;
                    &lt;select class="form-control select2" name="msbcb" style="width: 100%;"&gt;
                      &lt;option selected="selected"&gt;&lt;/option&gt;
                      &lt;?php
                      foreach ($player as $row) {
                        echo '&lt;option value="'.$row-&gt;player_id.'"&gt;'.$row-&gt;player_name.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Stumped by&lt;/label&gt;
                    &lt;select class="form-control select2" name="msbsb" style="width: 100%;"&gt;
                      &lt;option selected="selected"&gt;&lt;/option&gt;
                      &lt;?php
                      foreach ($player as $row) {
                        echo '&lt;option value="'.$row-&gt;player_id.'"&gt;'.$row-&gt;player_name.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Ranout Direct By&lt;/label&gt;
                    &lt;select class="form-control select2" name="msbrodb" style="width: 100%;"&gt;
                      &lt;option selected="selected"&gt;&lt;/option&gt;
                      &lt;?php
                      foreach ($player as $row) {
                        echo '&lt;option value="'.$row-&gt;player_id.'"&gt;'.$row-&gt;player_name.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Ranout Player 1&lt;/label&gt;
                    &lt;select class="form-control select2" name="msbro1" style="width: 100%;"&gt;
                      &lt;option selected="selected"&gt;&lt;/option&gt;
                      &lt;?php
                      foreach ($player as $row) {
                        echo '&lt;option value="'.$row-&gt;player_id.'"&gt;'.$row-&gt;player_name.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                    &lt;label&gt;Ranout Player 2&lt;/label&gt;
                    &lt;select class="form-control select2" name="msbro2" style="width: 100%;"&gt;
                      &lt;option selected="selected"&gt;&lt;/option&gt;
                      &lt;?php
                      foreach ($player as $row) {
                        echo '&lt;option value="'.$row-&gt;player_id.'"&gt;'.$row-&gt;player_name.'&lt;/option&gt;';
                      }?&gt;
                    &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;td&gt;
                    &lt;input type="submit" name="save" value="Submit" class="btn btn-block btn-primary btn-lg"&gt;
                  &lt;/td&gt;
                &lt;/form&gt;
              &lt;/div&gt;
              &lt;!-- /.box-body --&gt;
            &lt;/div&gt;
            &lt;!-- /.box --&gt;
          &lt;/div&gt;
          &lt;!--/.col (right) --&gt;
        &lt;/div&gt;
        &lt;!-- /.row --&gt;
      &lt;/section&gt;
      &lt;!-- /.content --&gt;
    &lt;/div&gt;
  &lt;script src="http://localhost/cd/assets/bower_components/jquery/dist/jquery.min.js"&gt;&lt;/script&gt;
  &lt;!-- jQuery --&gt;
  &lt;script src="http://localhost/cd/assets/bower_components/jquery/dist/jquery.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><strong>My jquery</strong> </p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
  
      $(document).ready(function() {
          $('select[name="minfmname"]').on('change', function() {
              var matchID = $(this).val();
              if(matchID) {
                  $.ajax({
                      url: '&lt;?php echo site_url('matchcon/getteambymatch');?&gt;'+matchID,
                      type: "POST",
                      dataType: "json",
                      success:function(teams) {
                          $('select[name="mteamid"]').empty();
                          $.each(teams, function(key, value) {
                              $('select[name="mteamid"]').append('&lt;option value="'+ value.team.team_id +'"&gt;'+ value.team.team_name +'&lt;/option&gt;');
                          });
                      }
                  });
              }else{
                  $('select[name="mteamid"]').empty();
              }
          });
      });
  &lt;/script&gt;
  </code></pre>