Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. <script>
  3. function tampilkan(){
  4. var kategori = document.getElementById("form1").kategori.value;
  5. if (kategori=="Gula")
  6. {
  7. document.getElementById("harga").value = '21500';
  8. }
  9. else if (kategori=="Sound")
  10. {
  11. document.getElementById("harga").value = '51500';
  12. }
  13. else if (kategori=="Kipas Angin")
  14. {
  15. document.getElementById("harga").value = '151500';
  16. }
  17. else if (kategori=="Lampu Belajar")
  18. {
  19. document.getElementById("harga").value = '71500';
  20. }
  21. }
  22. </script>
  23. <form action="4.php" method="post" id="form1" name="form1">
  24. Barang : <select id="kategori" name="kategori" onchange="tampilkan()">
  25. <option value="" disabled selected>Pilih</option>
  26. <option value="Gula">Gula</option>
  27. <option value="Sound">Sound</option>
  28. <option value="Kipas Angin">Kipas Angin</option>
  29. <option value="Lampu Belajar">Lampu Belajar</option>
  30. </select><br>
  31. Harga : <input name="harga" id="harga" type="text" readonly="true"><br>
  32. Bayar : <input name="bayar" type="text"><br>
  33. <input type="submit">
  34. </form>
  35.  
  36. <?php
  37. if(isset($_POST["kategori"])){
  38. $harga = $_POST['harga'];
  39. $bayar = $_POST['bayar'];
  40.  
  41.  
  42. $Uang=$bayar-$harga;
  43. $Pecahan2=$Uang/50000;
  44. $Sisa1=$Uang%50000;
  45. $Pecahan3=$Sisa1/20000;
  46. $Sisa2=$Sisa1%20000;
  47. $Pecahan4=$Sisa2/10000;
  48. $Sisa3=$Sisa2%10000;
  49. $Pecahan5=$Sisa3/5000;
  50. $Sisa4=$Sisa3%5000;
  51. $Pecahan6=$Sisa4/2000;
  52. $Sisa5=$Sisa4%2000;
  53. $Pecahan7=$Sisa5/1000;
  54. $Sisa6=$Sisa5%1000;
  55. $Pecahan8=$Sisa6/500;
  56. $Sisa7=$Sisa6%500;
  57. echo 'Jumlah Uang:Rp.'.number_format($Uang),'<br/>';
  58. echo '<br/>';
  59. echo 'Pecahan Rp.50000 = '.(int) $Pecahan2.' Lembar';
  60. echo '<br/>';
  61. echo 'Pecahan Rp.20000 = '.(int) $Pecahan3.' Lembar';
  62. echo '<br/>';
  63. echo 'Pecahan Rp.10000 = '.(int) $Pecahan4.' Lembar';
  64. echo '<br/>';
  65. echo 'Pecahan Rp.5000 = '.(int) $Pecahan5.' Lembar';
  66. echo '<br/>';
  67. echo 'Pecahan Rp.2000 = '.(int) $Pecahan6.' Lembar';
  68. echo '<br/>';
  69. echo 'Pecahan Rp.1000 = '.(int) $Pecahan7.' Lembar';
  70. echo '<br/>';
  71. echo 'Pecahan Rp.500 = '.(int) $Pecahan8.' Koin';
  72. }
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement