Advertisement
EnggarHakim

calc

Aug 23rd, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>Kalkulator</title>
  4. <script language="JavaScript" type="text/javascript">
  5. <!--
  6. function hitung(){
  7. var myForm = document.form1;
  8. var x=eval(myForm.x.value);
  9. var y=eval(myForm.y.value);
  10. var pil= myForm.opt.value;
  11. if (pil == "tambah") {
  12. var z = x + y;
  13. }else if (pil == "kurang") {
  14. var z = x - y;
  15. } else if (pil == "kali") {
  16. var z = x * y;
  17. } else if (pil == "bagi") {
  18. var z = x / y;
  19. }
  20. myForm.hasil.value = z;
  21. myForm.x.value = "";
  22. myForm.y.value = "";
  23. }
  24. function resetForm(){
  25. document.form1.reset();
  26. }
  27. //-->
  28. </script>
  29. </head>
  30. <body>
  31. <form name="form1" action="#">
  32. <input type="text" name="x" />
  33. <select name="opt">
  34. <option value="tambah"> + </option>
  35. <option value="kurang"> - </option>
  36. <option value="kali"> * </option>
  37. <option value="bagi"> / </option>
  38. </select>
  39. <input type="text" name="y" />
  40. <input type="button" value="=" onClick="hitung()" />
  41. <input type="text" name="hasil" disabled="true" /><br/>
  42. <input type="button" value="CLEAR" onClick="resetForm()" />
  43. </form>
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement