RommyRIsyandi

masalah function hitung jquery

Aug 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <div style="overflow-y: scroll; width: 100%"><table id="example3" class="table table-bordered table-hover table-striped" style="width: 100%">
  2.  
  3.     <thead>
  4.   <th>ID Menu</th>
  5.   <th>Nama Menu</th>
  6.   <th>Harga Satuan</th>
  7.   <th>Kategori</th>
  8.   <th>Jumlah Porsi</th>
  9.   <th>Subtotal</th>
  10.   <th>Aksi</th>
  11.  
  12. </thead>
  13. <tbody>
  14.  
  15.      <?php  foreach ($data as $row => $r) {
  16.      
  17.      ?>
  18.  
  19.      
  20.   <tr>
  21.     <?php echo form_open_multipart('admin/apesan'); ?>
  22.  
  23.       <td><input type="text" name="id_menu" value="<?php echo $r->id_menu?>" readonly></td>
  24.       <td><input type="text" name="nama_pesanan" value="<?php echo $r->nama_menu?>" readonly></td>
  25.       <td><input type="text" id="harga_satuan" class="harga_satuan" name="harga_satuan" onkeyup="hitung()" value="<?php echo $r->harga; ?>" readonly></td>
  26.       <td><?php echo $r->kategori; ?></td>
  27.       <td><input type="number" name="jml_porsi" id="jml_porsi" class="jml_porsi" onkeyup="hitung()"></td>
  28.       <td><input type="text" name="subtotal" id="subtotal" class="subtotal" readonly></td>
  29.       <td><a href="<?php echo base_url('admin/apesan') ?>"><button type="submit">Masukkan</button></td></tr>
  30.    <?php echo form_close();; ?>
  31.  <?php } ?>
  32.  
  33.    
  34.  
  35.  
  36. </tr></tbody></table><br/>
  37. </div>
  38. <script>
  39.  function hitung() {
  40.    var a = $(".harga_satuan").val();
  41.    var b = $(".jml_porsi").val();
  42.    c = a * b;
  43.    $(".subtotal").val(c);
  44.  }
  45. function isNumberKey(evt){
  46.   var charCode = (evt.which) ? evt.which : event.keyCode;
  47.   if (charCode != 46 && charCode > 31 && (charCode  < 48 || charCode  > 57))
  48.     return false;
  49.       return true;
  50. </script>
Advertisement
Add Comment
Please, Sign In to add comment