javascript - How to change a dropdown into a table format? -


i have fetch data through ajax database in dropdown format.

now want change dropdown list table. beginner ajax... have done many of efforts, convert table looking difficult task me.

below complete code.

<script type="text/javascript"> function select_std(){   var ali=$('#class_std').val();   $('#std_name').html('');   $.ajax({     url:"<?php echo base_url().'admin/test/'?>"+ali,     type:"get",     success:function(res){       $('#std_name').append(res);     }   }); }  </script> 

this controller

public function test($id=''){   $table='students';   $columns=array('*');   $where=array('c_id'=>$id);   $data['rcd']= $this->crud->get_records($table, $columns, $where)->result();    foreach ($data['rcd'] $value) {     $output = "<option value='".$value->std_id."'>".$value->name."</option>";     echo $output;   } } 


<div class="col-sm-2">   <select id="class_std" name="c_id" class="form-control selectboxit" onchange="select_std()">      <?php      $classes = $this->db->get('classes')->result_array();     foreach($classes $row):     ?>     <option value="<?php echo $row['c_id'];?>">       <?php echo $row['c_name'];?>     </option>     <?php     endforeach;     ?>   </select> </div> 

here database displaying

<div class="col-md-6">   <select id="std_name" class="form-control">    </select> </div> 

i agree complaints above, despite shortcomings in question, see if rocks boat:

/* js */  function select_std(){    var ali=$('#class_std').val();    $.ajax({      url:"<?php echo base_url().'admin/test/'?>"+ali,      type:"get",      success:function(res){        $('#mytable tbody').append(res);      }    });  }
<?php  /* controller - replace old 1 one */  public function test($id=''){    $table='students';    $columns=array('*');    $where=array('c_id'=>$id);    $data['rcd']= $this->crud->get_records($table, $columns, $where)->result();      foreach ($data['rcd'] $value) {      $output = "<tr><td>".$value->std_id."</td><td>".$value->name."</td></tr>";      echo $output;    }  }  ?>  <div class="col-sm-2">    <select id="class_std" name="c_id" class="form-control selectboxit" onchange="select_std()">        <?php       $classes = $this->db->get('classes')->result_array();      foreach($classes $row):      ?>      <option value="<?php echo $row['c_id'];?>">        <?php echo $row['c_name'];?>      </option>      <?php      endforeach;      ?>    </select>  </div>  <div class="col-md-6">        <table id="mytable">            <thead>                <th>student id</th>                <th>name</th>            </thead>            <tbody>                            </tbody>        </table>  </div>


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -