<!DOCTYPE html>
<html lang="en">
<head>
<title>Kalkulator Sederhana</title>
<script type="text/javascript" src="rumus.js"></script>
</head>
<p>
<h2>Program Kalkulator Sederhana</h2>
</p>
<body>
<form name="form1" action="#"><input type="text" name="a"/>
<select name="opt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" name="b"/>
<input type="button" value="=" onClick="hitung()"/>
<input type="text" name="hasil" disabled="true"/><br/>
<input type="button" value="clear" onClick="resetForm()"/>
</form>
</body>
</html>
---->> Buat file baru dengan nama rumus.js
function hitung(){
var myForm = document.form1;
var a=eval(myForm.a.value);
var b=eval(myForm.b.value);
var pil= myForm.opt.value;
if (pil == "+") {
var c = a + b;
}else if (pil == "-") {
var c = a - b;
} else if (pil == "*") {
var c = a * b;
} else if (pil == "/") {
var c = a / b;
}
myForm.hasil.value = c;
}
function resetForm(){
document.form1.reset();
}
//-->
Tidak ada komentar:
Posting Komentar