Advertisement
hafidh

JS - onBlur

Dec 26th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <script>
  3.     function update(){
  4.         hasil = document.getElementById("hasil");
  5.         jumlah = document.getElementById("jumlah").value;
  6.         harga = document.getElementById("harga").value;
  7.         if(!isNaN(jumlah) && !isNaN(harga)){
  8.             total = jumlah * harga;
  9.             hasil.innerHTML = "Total = "+total;
  10.         }else{
  11.             alert("Inputan harus angka");
  12.         }
  13.     }
  14. </script>
  15. <head>
  16.     <title>
  17.     TES
  18.     </title>
  19. </head>
  20. <body>
  21.     Jumlah :<input type="text" id="jumlah" onblur="update()" value="0"><br/>
  22.     Harga :<input type="text" id="harga" onblur="update()" value="0"><br/>
  23.     <div id="hasil">
  24.         0
  25.     </div>
  26. </body>
  27. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement