Advertisement
cdsatrian

with jQuery

Jun 12th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2. //........truncated code ..............
  3. $gTotal = 0;
  4. while($menu=mysql_fetch_array($pesanan))
  5. {
  6. $tot=$menu[harga]*$menu[jumlah];
  7. echo "<tr>\n"
  8.     ."<td>$menu[nama_menu]</td>\n"
  9.     ."<td><div align='center'>$menu[jumlah]</td></div>\n"
  10.     ."<td><div align='center'>$menu[harga]</td></div>\n"
  11.     ."<td><div align='center'>$tot</td></div>";
  12. $gTotal = $gTotal + $tot;
  13. }
  14. echo "</tr></table>";
  15.     ."Total Pembelian Anda : Rp. $gTotal<br />\n"
  16.     ."Bayar : Rp. <input name='bayar' type='text' id='bayar' />\n"
  17.     ."<input name='proses' type='submit' id='proses' value='Click' />\n"
  18.     ."<input name='kembali' type='text' id='kembali'/>\n"
  19.     ."<input name='gTotal' type='hidden' id='gTotal' value='$gTotal' />\n" // add this line
  20.     ."</form>";
  21. ?>
  22. <script type="text/javascript">    
  23.         $('#proses').click(function(){
  24.       var  kembalian;
  25.             {
  26.               gTotal=parseFloat($('#gTotal').val().replace(/[^\d\.\-\ ]/g, ''));;
  27.               bayar=parseFloat($('#bayar').val().replace(/[^\d\.\-\ ]/g, ''));;
  28.               kembalian=gTotal-bayar;
  29.               $('#kembali').val(kembalian);
  30.             }
  31.         });
  32. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement