sebuahhobi

select option chained from radio button

Aug 15th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <!--Script Ajax-->
  2. <script type="text/javascript">
  3.  
  4. $(function(){
  5.  
  6. $.ajaxSetup({
  7. type:"POST",
  8. url: "<?php echo base_url('index.php/select/ambil_data') ?>",
  9. cache: false,
  10. });
  11.  
  12. $("#j_kI").change(function(){
  13.  
  14. var value=$(this).val();
  15. if(value>0){
  16. $.ajax({
  17. data:{modul:'kamar_ikhwan',id:value},
  18. success: function(respond){
  19. $("#kamar").html(respond);
  20. }
  21. })
  22. }
  23.  
  24. });
  25. $("#j_kA").change(function(){
  26.  
  27. var value=$(this).val();
  28. if(value>0){
  29. $.ajax({
  30. data:{modul:'kamar_akhwat',id:'value'},
  31. success: function(respond){
  32. $("#kamar_akhwat").html(respond);
  33. }
  34. })
  35. }
  36.  
  37. });
  38.  
  39. })
  40.  
  41. </script>
  42. <!--END script ajax-->
  43.  
  44. <!--COntrollel-->
  45. function ambil_data(){
  46.  
  47.         $modul=$this->input->post('modul');
  48.         $id=$this->input->post('id');
  49.         //kamar
  50.         if($modul=="kamar"){
  51.             echo $this->model_select->kamar_ikhwan();
  52.         }
  53.         elseif($modul=="kamar_akhwat"){
  54.             echo $this->model_select->kamar_akhwat();
  55.         }
  56.        
  57.     }
  58. <!-- END COntrollel-->
  59.  
  60. <!--HTML-->
  61. <div class="form-group">
  62.                         <label class="control-label col-md-3 col-sm-3 col-xs-12">Jenis Kelamin
  63.                         </label>
  64.                         <div class="col-md-6 col-sm-6 col-xs-12">
  65.                             Laki-laki: <input type="radio" class="flat" name="j_k" id='j_kI' value="<?php echo $j_k; ?>" checked="" />
  66.                             Perempuan: <input type="radio" class="flat" name="j_k" id="j_kA" value="<?php echo $j_k; ?>" />
  67.                         </div>
  68.             </div>
  69. <div class="form-group">
  70.             <label class="control-label col-md-3 col-sm-3 col-xs-12" for="varchar">Kamar <?php echo form_error('kamar') ?></label>
  71.                 <div class="col-md-6 col-sm-6 col-xs-12">
  72.                     <select class='form-control' id='kamar' name="kamar">
  73.                         <option value='0'>--pilih--</option>
  74.                        
  75.                     </select>
  76.                 </div>
  77.         </div>
  78. <!--END HTML-->
  79.  
  80. <!--Model-->
  81. function kamar_akhwat(){
  82.         $kamar="<option value='0'>--pilih--</pilih>";
  83.  
  84.         $this->db->order_by('kamar','ASC');
  85.         $jur= $this->db->get('kamar_akhwat');
  86.  
  87.         foreach ($jur->result_array() as $data ){
  88.             $jur1.= "<option value='$data[id]'>$data[kamar]</option>";
  89.         }
  90.     return $jur1;
  91.     }
  92.     function kamar_ikhwan(){
  93.         $kamar="<option value='0'>--pilih--</pilih>";
  94.  
  95.         $this->db->order_by('kamar','ASC');
  96.         $jur= $this->db->where('kamar');
  97.  
  98.         foreach ($jur->result_array() as $data ){
  99.             $jur1.= "<option value='$data[id]'>$data[kamar]</option>";
  100.         }
  101.     return $jur1;
  102.     }
  103. <!--END model-->
Add Comment
Please, Sign In to add comment