Advertisement
zulmi

tambah.php tutorial combobox_1

Nov 26th, 2017
2,533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.67 KB | None | 0 0
  1.  
  2. <script type="text/javascript">
  3.  
  4.     function call_kab () {
  5.        
  6.         var prov = $('#provinsi option:selected').val();
  7.         //alert(prov);
  8.         if (prov == 0) {
  9.             alert("Pilih Provinsi");
  10.         }else{
  11.             // $('#kabupaten').show();
  12.         //alert(prov);
  13.         $.ajax({
  14.             url:"<?php echo $this->createUrl('/Combobox/get_kab'); ?>",
  15.             type:'POST',
  16.             data:{ prov:prov },
  17.             success:function(data){
  18.                 $('#kab').html(data);
  19.             }
  20.           })
  21.         }
  22.     };
  23.  
  24.     function call_kec () {
  25.        
  26.         var kab = $('#kab option:selected').val();
  27.         //alert(kab);
  28.         if (kab == 0) {
  29.             alert('Input required !');
  30.         }else{
  31.             // $('#kecamatan').show();
  32.         //alert(prov);
  33.         $.ajax({
  34.             url:"<?php echo $this->createUrl('/Combobox/get_kec'); ?>",
  35.             type:'POST',
  36.             data:{ kab:kab },
  37.             success:function(data){
  38.                 $('#kec').html(data);
  39.             }
  40.           })
  41.         }
  42.      };
  43.  
  44.      function call_kel () {
  45.        
  46.         var kel = $('#kec option:selected').val();
  47.         //alert(kab);
  48.         if (kel == 0) {
  49.             alert('Input required !');
  50.         }else{
  51.             // $('#kecamatan').show();
  52.         //alert(prov);
  53.         $.ajax({
  54.             url:"<?php echo $this->createUrl('/Combobox/get_kel'); ?>",//link to url ComboboxController actionGet_Kel
  55.             type:'POST',
  56.             data:{ kel:kel },
  57.             success:function(data){
  58.                 $('#des').html(data);
  59.             }
  60.           })
  61.         }
  62.      };
  63.      </script>
  64.  
  65. <form method="post" action="<?php echo $this->createUrl('/Combobox/tambah'); ?>">
  66.  
  67.                
  68.             <div class="form">
  69.                 <select name="province" id="provinsi" onchange="call_kab(this)" >  
  70.  
  71.                 //onchange berfungsi untuk mengeksekusi function call_kab jquery
  72.                 <option value="0">--Pilih Provinsi--</option>
  73.                     <?php
  74.                       $criteria = new CDbCriteria;
  75.                      $criteria->order = 'nama ASC';
  76.                         $prov = Provinsi::model()->findAll($criteria);
  77.                         foreach($prov as $p)
  78.                         {
  79.                             echo '<option value="'.$p['id_prov'].'">'.$p['nama'].'</option>';
  80.                         }
  81.                     ?>
  82.                 </select>
  83.             </div>
  84.  
  85.             <div class="form">
  86.             <label >Kota/Kab.</label>
  87.                 <select id="kab" name="kabupaten" onchange="call_kec(this)" >
  88.                 <option value="0">--Pilih kabupaten--</option>
  89.                 </select>
  90.             </div>
  91.  
  92.             <div class="form">
  93.                 <label>Kecamatan</label>
  94.                 <select id="kec" name="kecamatan" onchange="call_kel(this)" >
  95.                 <option value="0">--Pilih kecamatan--</option>
  96.                 </select>
  97.             </div>
  98.  
  99.                 <div class="form">
  100.                 <label>kelurahan</label>
  101.                 <select id="des" name="kelurahan">
  102.                 <option value="0">--Pilih kelurahan--</option>
  103.                 </select>
  104.             </div>
  105.  
  106.             <div class="form">
  107.                 <label>Biaya pengiriman</label>
  108.                 <input type="text" name="harga">
  109.                 </select>
  110.             </div>
  111.  
  112.             <div class="form">
  113.                 <input type="submit" name="addsubmit" class="btn" value="Simpan">
  114.             </div>
  115.  
  116.             </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement