Welcome Guest, Not a member yet? Register   Sign In
Dependent drop down not displaying anything

I have this simple dropdown menu in my codeigniter form. When clicking dzongkhag(district) it should display the list of geogs(towns), but, instead it do not do so. Only the list of geog(town) is populated from the database table. The drop down menu that I have is not the best one but that is what I could come up with after trying (for many weeks) many times unsuccessfully. I will be grateful if someone could help me out/solve/advice on this.

Here are the snippets
<label >Dzongkhag: </label>
<select id="user_dzongkhag" name="dzongkhag" >
  <option>Select Dzongkhag</option>
  <option value="Bumthang">Bumtang</option>
  <option value="Chhukha">Chhukha</option>
  <option value="Dagana">Dagana</option>
  <option value="Gasa">Gasa</option>
  <option value="Haa">Haa</option>
  <option value="Lhuentse">Lhuntse</option>
  <option value="Monggar">Monggar</option>
  <option value="Paro">Paro</option>
  <option value="Pema Gatshel">Pema Gatshel</option>
  <option value="Punakha">Punakha</option>
  <option value="Samdrup Jongkhar">Samdrup Jongkhar</option>
  <option value="Samtse">Samtse</option>
  <option value="Sarpang">Sarpang</option>
  <option value="Thimphu">Thimphu</option>
  <option value="Trashigang">Trashigang</option>
  <option value="Trashi Yangtse">Trashi Yangtse</option>
  <option value="Trongsa">Trongsa</option>
  <option value="Tsirang">Tsirang</option>
  <option value="Wangdue Phodrang">Wangdue Phodrang</option>
  <option value="Zhemgang">Zhemgang</option>                
<label >Geog:</label>
<select id="user_geog" name="geog" >
  <option> select geog</option>
Java script code, I have written it inside the view.php file
    $('#user_geog').html('<option> Fetching...</option>');

    var user_dzongkhag =$('#user_dzongkhag').val();



      url:"<?php echo site_url('ajax/select_auth_geog/'); ?>",
public function select_auth_geog(){
  $user_dzongkhag= $this->input->post('user_dzongkhag');
  foreach ($returnGeog as $key) {
    echo '<option value="'.$key['name'].'">'.$key['name'].' </option>';
public function select_auth_geog($user_dzongkhag){
Is there anything I need to change?

Hey karmad

Be good if you could post up the whole function in the model. Also are there any errors coming back on the request or is it empty? You can check using developer tools on your browser eg Chrome via the network tab.

Instead of
PHP Code:
PHP Code:
data: { "user_dzongkhag" user_dzongkhag }, 

You can also save yourself a lot of time and effort if you put the district names in an array (in your controller). You can pass this array to your view to build the list of districts. And you can pass it to your model to determine which cities belong to the selected district.

Theme © iAndrew 2016 - Forum software by © MyBB