Ianpanrita = Irhamullah

Irhamullah

Di Atas Bumi Di Bawah Langit
Irhamullah

SourceCode JavaScript Calculator

April 5, 2012, by ianpanrita, category blogs, JavaScript

Hi guys, I want to share my source code about JavaScript Calculator

You can see demo in here Calculator

<html>
<head>
<title>JAVASCRIPT CALCULATOR</title>
<script language="javascript" type="text/javascript">
<!--
var flag = false;
function isi(num) {
if (flag) calc.b.value += num;
else calc.a.value += num;
}
// untuk penjumlahan
function tambah()
{
calc.opr.value = ' + ' // operator yg digunakan +
flag = true;
calc.b.focus()
}
// untuk pengurangan
function kurang()
{
calc.opr.value = ' - '
flag = true;
calc.b.focus()
}
// untuk perkalian
function kali()
{
calc.opr.value = ' * '
flag = true;
calc.b.focus()
}
// untuk pembagian
function bagi()
{
calc.opr.value = ' / '
flag = true;
calc.b.focus()
}
// untuk mengkosongkan form
function kosong()
{
calc.a.focus()
calc.a.value=""
calc.opr.value=""
calc.b.value=""
calc.c.value=""
flag = false;
}
//-->
</script>
<style type="text/css">
p {
font-family:verdana;
font-size:10px;
line-height:1.6em;
font-weight:bold;
color:#727272
}
</style>
</head>
<body onload=kosong()>
<center>
<p style="padding:20px 0px 30px 0px"><font size="4">JavaScript Calculator<br />Tugas Teknologi Web</font></p>
<form name="calc">
<table border="4" bordercolor="red">
<tr>
<td>
<input type="text" name="a" size="2" />
<input type="text" name="opr" size="1" />
<input type="text" name="b" size="2" /> =
<input type="text" name="c" size="2" />
<br/>
</td>
</tr>
<tr>
<td>
<input type="button" name="one"   value="  1  " onclick="isi(1)" />
<input type="button" name="two"   value="  2  " onclick="isi(2)" />
<input type="button" name="three" value="  3  " onclick="isi(3)" />
<input type="button" name="plus"  value="  +  " onclick="tambah()" />
<br/>
<input type="button" name="four"  value="  4  " onclick="isi(4)" />
<input type="button" name="five"  value="  5  " onclick="isi(5)" />
<input type="button" name="six"   value="  6  " onclick="isi(6)" />
<input type="button" name="minus" value="  -  " onclick="kurang()" />
<br/>
<input type="button" name="seven" value="  7  " onclick="isi(7)" />
<input type="button" name="eight" value="  8  " onclick="isi(8)" />
<input type="button" name="nine"  value="  9  " onclick="isi(9)" />
<input type="button" name="minus" value="  x  " onclick="kali()" />
<br/>
<input type="button" name="clear" value="  c  " onclick="kosong()" />
<input type="button" name="zero"  value="  0  " onclick="isi(0)" />
<input type="button" name="DoIt"  value="  =  " onclick="calc.c.value=eval(calc.a.value+calc.opr.value+calc.b.value)" />
<input type="button" name="minus" value="  /  " onclick="bagi()" />
<br/>
</td>
</tr>
</table>
</form>
<p>Created by : <br/>Irhamullah</p><hr/>
<p>2012 &copy; ianpanrita.com . All Rights Reserved.</p>
</center>
</body>
</html>

You can see demo in here Calculator.

2 Comments

So, what do you think ?