Membuat Calculator #1
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hitung</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
function hitung(){
var mf=document.form1;
if (mf.op.value == "+")
mf.bil3.value=parseFloat(mf.bil1.value) + parseFloat(mf.bil2.value);
else if (mf.op.value == "-")
mf.bil3.value=parseFloat(mf.bil1.value) - parseFloat(mf.bil2.value);
else if (mf.op.value == "*")
mf.bil3.value=parseFloat(mf.bil1.value) * parseFloat(mf.bil2.value);
else
mf.bil3.value=parseFloat(mf.bil1.value) / parseFloat(mf.bil2.value);
}
//-->
</script>
<form name=form1 action="#">
<input type=text name=bil1>
<select name="op">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type=text name=bil2>
<input type="button" value="=" onClick="hitung()" />
<input type=text name=bil3>
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar