Advertisement
GWibisono

pelari ini

Oct 9th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. error_reporting(1);
  3. if($_GET['act']=='add')
  4. {
  5.     $code=$_POST['id'];
  6.     //query disini
  7.    
  8.     $s="<tr><td>$code</td>
  9.     <td>nama buku dengan kode $code
  10.      </td>
  11.     <td>1000 <input type=hidden name='price[$code]'
  12.     value='1000' class='price' /></td></tr>";
  13.    
  14.     $a=array('tbl'=>$s);
  15.     $json=json_encode($a);
  16. die($json);
  17. }
  18. ?><script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  19.  
  20. pilih buku
  21. <select onchange='addRow()' class='buku'><option>PILIH BUKU
  22. <?php
  23. for($i=100; $i<120; $i++)
  24. {
  25.     echo "<option value='$i'>buku kode ke $i ";
  26. }
  27. ?>
  28. </select>
  29. <table>
  30. <thead><th>kode</th><th>judul</th><th>harga</th></thead>
  31. <tbody class='listBuku'></tbody>
  32. <tfooter>
  33. <tr><td>&nbsp;</td><td>&nbsp;</td><td><span class='jumlah'>&nbsp;</span></td></tr>
  34. </tfooter>
  35. </table>
  36.  
  37.  
  38. <p>
  39. setelah pilih dari list buku di atas, maka akan jalanin addRow.php?id={id yg dipilih dari select}
  40. lalu setelah dapet isinya.. (bentuk json)<br/>
  41. maka akan di append ke tbody yg ada dibawah<br/>
  42. untuk hitung berapa total bayarnya.. pake script jquery each yg mana hrs dibuat jalan dgn interval (ato bs jalan dgn trigger dari km input / appen lalu sekalian update harga)
  43. </p>
  44. <script>
  45. function addRow()
  46. {
  47.  
  48.     var request = $.ajax({
  49.           url: "?act=add",
  50.           type: "POST",
  51.           data: {id: $('.buku').val()},
  52.           dataType: "json"
  53.     });
  54.    
  55.     request.success(function(msg) {
  56.       console.log('data sudah terkirim');
  57.         $(".listBuku").append(msg.tbl);
  58.         checkHarga();
  59.     });
  60. }
  61.  
  62. function checkHarga()
  63. {
  64.     n=0;
  65.     $( ".price" ).each(function( index ) {
  66.       console.log( index + ": " + $( this ).val() );
  67.       n+=parseInt($(this).val());
  68.     });
  69.  
  70.     $(".jumlah").text( n);
  71. }
  72. </script>
  73. /*
  74. silakan dipelajari
  75. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement