Advertisement
Guest User

Untitled

a guest
May 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Operasi Hitung Aljabar</title>
  5.     <link rel="stylesheet" type="text/css" href="<?php echo base_url()."assets/";?>style.css">
  6. </head>
  7. <body>
  8.     <?php
  9.     if(isset($_POST['hitung'])){
  10.         $bil1 = $_POST['bil1'];
  11.         $bil2 = $_POST['bil2'];
  12.         $operasi = $_POST['operasi'];
  13.         switch ($operasi) {
  14.             case 'tambah':
  15.                 $hasil = $bil1+$bil2;
  16.             break;
  17.             case 'kurang':
  18.                 $hasil = $bil1-$bil2;
  19.             break;
  20.             case 'kali':
  21.                 $hasil = $bil1*$bil2;
  22.             break;
  23.             case 'bagi':
  24.                 $hasil = $bil1/$bil2;
  25.             break;         
  26.         }
  27.     }
  28.     ?>
  29.     <div class="kalkulator">
  30.         <h2 class="judul">Operasi Hitung Aljabar</h2>
  31.         <!-- <a class="brand" href="https://www.malasngoding.com">www.malasngoding.com</a> -->
  32.         <form method="post" action="index.php">        
  33.             <input type="text" name="bil1" class="bil" autocomplete="off" placeholder="Masukkan Bilangan Pertama">
  34.             <input type="text" name="bil2" class="bil" autocomplete="off" placeholder="Masukkan Bilangan Kedua">
  35.             <select class="opt" name="operasi">
  36.                 <option value="tambah">+</option>
  37.                 <option value="kurang">-</option>
  38.                 <option value="kali">x</option>
  39.                 <option value="bagi">/</option>
  40.             </select>
  41.             <input type="submit" name="hitung" value="Hitung" class="tombol">                                          
  42.         </form>
  43.         <?php if(isset($_POST['hitung'])){ ?>
  44.             <input type="text" value="<?php echo $hasil; ?>" class="bil">
  45.         <?php }else{ ?>
  46.             <input type="text" value="0" class="bil">
  47.         <?php } ?>         
  48.     </div>
  49.     <script>
  50.             function myFunction() {
  51.               alert("Hello! I am an alert box!");
  52.             }
  53.             myFunction() // cari menulis pemanggilan function
  54.     </script>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement