使用codeigniter选择显示选项

I want to ask for my code option selected with 2 tabel in page register

table prodi
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| id_prodi    | varchar(3)  | NO   | PRI | NULL    |       |
| nama_prodi  | varchar(30) | NO   |     | NULL    |       |
| id_fakultas | varchar(3)  | NO   | MUL | NULL    |       |
| id          | int(2)      | NO   | MUL | NULL    |       |
+-------------+-------------+------+-----+---------+-------+

and

table jurusan
+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| id_fakultas   | varchar(3)  | NO   | PRI | NULL    |       |
| nama_fakultas | varchar(40) | NO   |     | NULL    |       |
+---------------+-------------+------+-----+---------+-------+

here's view :

 <label for="fakultas">Fakultas : </label>
  <select id="fakultas" name="fakultas_user"  onChange="fakultas">

    <?php 
      foreach ($qfakultas as $fakultas) {
        echo "<option value=".$fakultas->kd_fakultas.">".$fakultas->nama_fakultas."</option>";    
      }
    ?>    
  </select>

  <hr>

  <label for="jurusan">Jurusan  : </label>
  <select id="jurusan" name="jurusan_user" onChange="jurusan">
    <?php 
      foreach ($qprodi as $prodi) {
        echo "<option value=".$prodi->kd_prodi.">".$prodi->nama_prodi."</option>";    
      }
    ?>  
  </select>

but I will display 'nama_prodi' based on 'id_fakultas"

register with option value

How to display when I click 'nama_fakultas' then display 'nama_prodi' based on 'id_fakultas' ?

Thanks

Here is the Ajax code that I can help, only to get nama_prodi based on id_falkutas.

You can use this code for your project, there is something you need to do.
Not just copy the code. Just a few step
(ID Lang : Jangan dicopy mentah2, hanya beberapa langkah saja untuk edit).

  1. Change YOUR_URL_HERE into your base_url() or create var for it.
  2. Change nama_controller into your controller name in CI_Controller
  3. Change nama_fungsi into your function to get the data from your model (database).
    Example : ambil_data_jurusan.
  4. Remove your foreach - echo <option> and onchange from your view.
  5. Add the script into your view files or create a new .js file.
  6. Please help me to mark as correct answer if this code helped you. ( tolong dibantu gan )

See Code Example :

<script>
$("#falkutas").on('change', function() {
   $.ajax({
        type:"POST",
        url:'YOUR_URL_HERE/nama_controller/nama_fungsi',
        data:{"falkutas_user":falkutas_user,"csrf_token":$("input[name=csrf_token]").val()},
        dataType:'json',
        success: function(result) {
            for(var i=0; i<result.length; i++) {
                res += '<option value="'+result[i]['id_prodi']+'">'+result[i]['nama_prodi']+'</option>';
            }
            $(document).ready(function() {
                 $("#prodi").html(res);
            });
        },
        error: function(result) {
            $(document).ready(function() {
                $("#prodi").html(''); //empty select value
            });
        }
    });
}
</script>

Then, in your function code :

// Inside function ambil_data_jurusan(), harusnya sudah jalan kalau gini
$return = $this->model->get_jurusan($this->input->post('falkutas',TRUE));
if(count($return)>0) {
    echo json_encode($return);
}

In your view, just let select empty like this.

<select id="jurusan" name="jurusan_user">

</select>