<html>
<head>
<title>Studi Kasus Modul 5</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
function hitung(){
var x=eval(document.form1.x.value);
var y=eval(document.form1.y.value);
var pil= document.form1.opt.value;
if (pil == "tambah") {
var z = x + y;
}
else if (pil == "kurang") {
var z = x - y;
}
else if (pil == "kali") {
var z = x * y;
}
else if (pil == "bagi") {
var z = x / y;
}
document.form1.hasil.value = z;
}
function resetForm(){
document.form1.reset();
}
//-->
</script>
<form name="form1" action="#">
<input type="text" name="x" />
<select name="opt">
<option value="tambah"> + </option>
<option value="kurang"> - </option>
<option value="kali"> * </option>
<option value="bagi"> / </option>
</select>
<input type="text" name="y" />
<input type="button" value="=" onClick="hitung()" />
<input type="text" name="hasil" disabled="true" /><br/>
<input type="button" value="Reset" onClick="resetForm()" />
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar