<html lang="en">
<html>
<head>
<title>Kalkulator Sederhana</title>
<link rel="stylesheet" href="kalkulator.css" type="text/css" />
</head>
<body>
<script language="javascript" type="text/javascript">
function tambah()
{
var myForm = document.form1;
if(myForm.bil1.value=="")myForm.bil1.value=0;
if(myForm.bil2.value=="")myForm.bil2.value=0;
myForm.total.value = parseInt(myForm.bil1.value) + parseInt(myForm.bil2.value);
}
function kurang()
{
var myForm = document.form1;
if(myForm.bil1.value=="")myForm.bil1.value=0;
if(myForm.bil2.value=="")myForm.bil2.value=0;
myForm.total.value = parseInt(myForm.bil1.value) - parseInt(myForm.bil2.value);
}
function kali()
{
var myForm = document.form1;
if(myForm.bil1.value=="")myForm.bil1.value=0;
if(myForm.bil2.value=="")myForm.bil2.value=0;
myForm.total.value = parseInt(myForm.bil1.value) * parseInt(myForm.bil2.value);
}
function bagi()
{
var myForm = document.form1;
if(myForm.bil1.value=="")myForm.bil1.value=0;
if(myForm.bil2.value=="")myForm.bil2.value=0;
myForm.total.value = parseInt(myForm.bil1.value) / parseInt(myForm.bil2.value);
}
function clean()
{
var myForm = document.form1;
myForm.bil1.value="";
myForm.bil2.value="";
myForm.total.value="";
}
</script>
<header>
Kalkulator Sederhana Dengan JavaScript
</header>
<section>
<form name=form1 action="#">
Bilangan 1<br />
<input type="text" name="bil1" /><br /><br />
Bilangan 2<br />
<input type="text" name="bil2" /><br /><br />
Hasil<br />
<input type="text" name="total" readonly /><br /><br />
Operator<br />
<input type="button" value="+" onClick="tambah()" />
<input type="button" value="-" onClick="kurang()" />
<input type="button" value="*" onClick="kali()" />
<input type="button" value="/" onClick="bagi()" /><br /><br />
</form>
</section>
</body>
</html>
Tidak ada komentar:
Posting Komentar