Advertisement
Guest User

multiple dropdown_list

a guest
Jul 29th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. view Single_input.php
  2. <html>
  3.    <?php echo form_open('Petugas/submit');?>
  4.  
  5.  Jenis :<?php echo form_dropdown("id_jenisku",$jenisx,"","id='id_jenis'"); ?>
  6.  
  7.    <div id="tampil">
  8.         <?php
  9.        
  10.         echo form_dropdown("id_bay",array('Pilih Bay / Trafo'=>'Pilih Bay Dahulu'),'','disabled');
  11.  
  12.         echo form_dropdown("id_objek",array('Pilih Bay / Trafo'=>'Pilih Bay Dahulu'),'','disabled');
  13.         ?>
  14.  
  15.       <?php echo form_submit("submit","Submit"); ?>
  16.       <?php echo form_close(); ?>
  17.  
  18.         <script type="text/javascript">
  19.         $("#id_jenis").change(function(){
  20.                 var selectValues = $("#id_jenis").val();
  21.                 if (selectValues == 0){
  22.                     var msg = "Bay / Trafo :<br><select name=\"id_bay\" disabled><option value=\"Pilih Kota / Kabupaten\">Pilih Jenis Bay Dahulu</option></select>";
  23.                     $('#tampil').html(msg);
  24.                                 var msg2 = "Object Pengukuran :<br><select name=\"id_objek\" disabled><option value=\"Pilih Kota / Kabupaten\">Pilih Jenis Bay Dahulu</option></select>";
  25.                                 $('#tampil').html(msg2);
  26.                 }else{
  27.                     var id_jenis = {id_jenis:$("#id_jenis").val()};
  28.                     $('#id_bay').attr("disabled",true);
  29.                                 $('#id_objek').attr("disabled",true);
  30.                     $.ajax({
  31.                             type: "POST",
  32.                             url : "<?php echo site_url('Petugas/opt_select')?>",
  33.                             data: id_jenis,
  34.                             success: function(msg){
  35.                                 $('#tampil').html(msg);
  36.                             }
  37.                     });
  38.                 }
  39.                  });
  40.            
  41.        </script>
  42.        
  43. </body>
  44. </html>
  45.  
  46. view opt_act.php
  47.     <?php
  48.         echo form_dropdown("id_bay",$option_bay,'',"id='id_bay'");
  49.            
  50.     ?>
  51.  
  52.     <?php
  53.         echo form_dropdown("id_objek",$option_obj,'',"id='id_objek'");
  54.     ?>
  55.  
  56. Controller Petugas.php
  57.  
  58. function single_input_thermo()
  59.     {
  60.             $data['jenisx']= $this->petugas_model->get_jenis_opt();
  61.             $this->load->view('Petugas/Single_input',$data);
  62.     }
  63.  
  64.  
  65.     function opt_select()
  66.     {
  67.             if ('IS_AJAX'){
  68.                $idjenis=$this->input->post('id_jenis');
  69.                echo $idjenis;
  70.                $idgi=$this->session->userdata('gi');
  71.                $data['option_bay']=$this->petugas_model->get_bay_opt($idgi,$idjenis);
  72.                $data['option_obj']=  $this->petugas_model->get_objek_opt($idjenis);
  73.                $this->load->view('Petugas/opt_act',$data);
  74.     }
  75.  
  76.  
  77.    
  78.  
  79.      function submit(){
  80.             echo "Jenis Bay ".$this->input->post("id_jenisku");
  81.             echo "<br>";
  82.             echo "Nama Bay".$this->input->post("id_bay");
  83.             echo "<br>";
  84.             echo "Objek Bay ".$this->input->post("id_objek");
  85.       }
  86.  
  87. model petugas_model.php
  88. function get_jenis_opt()
  89.     {
  90.         $this->db->select('*');
  91.         $this->db->from('JENIS_BAY');
  92.         $jenis=$this->db->get();
  93.         foreach ($jenis->result() as $row) {
  94.                 $result[0]='pilih jenis';
  95.                 $result[$row->ID_JENIS]=$row->NAMA_JENIS;
  96.         }
  97.         return $result;
  98.     }
  99.  
  100.     function get_bay_opt($idgi,$idjenis)
  101.     {
  102.         $this->db->select('*');
  103.         $this->db->from('BAY');
  104.         $this->db->where('ID_GI',$idgi);
  105.         $this->db->where('ID_JENIS',$idjenis);
  106.         $bay=$this->db->get();
  107.         foreach ($bay->result() as $row) {
  108.                 $result[0]='pilih Bay';
  109.                 $result[$row->ID_BAY]=$row->NAMA_BAY;
  110.         }
  111.         return $result;
  112.        
  113.     }
  114.  
  115.     function get_objek_opt($idjenis)
  116.     {
  117.      
  118.         $this->db->select('*');
  119.         $this->db->from('OBJECT');
  120.         $this->db->where('ID_JENIS',$idjenis);
  121.         $objek=$this->db->get();
  122.         foreach ($objek->result() as $row) {
  123.                 $result1[0]='Pilih Objek';
  124.                 $result1[$row->ID_OBJECT]=$row->NAMA_OBJECT;
  125.         }
  126.         return $result1;
  127.  
  128.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement