Pages

Rabu, 11 Februari 2009

Memasang Kalkulator di Blog

Apabila Anda pernah melihat situs yang menjual produk-produk baik itu elektronik maupun busana, biasanya disana ada sebuah kalkulator yang disediakan di situs tersebut. Karena dengan adanya kalkulator, pengunjung bisa langsung memperkirakan berapa jumlah uang yang akan dibelanjakan oleh calon pembeli. Nah bagi Anda yang suka berjualan di Blog jangan khawatir, karena kita juga bisa memasang kalkulator di Blog.

Anda tinggal mengcopy paste script dibawah ini di halaman blog Anda, dan Anda bisa langsung menjalankan kalkulator tersebut.
<center>
<form action="" name="Keypad">

<!-- Original: http://www.dummyproof.com/javascripts -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Dimodifikasi oleh!! http://catatankecik.blogspot.com -->

<table>
<b>
<table border="2" width="50" cellpadding="1" cellspacing="5" height="60">
<tr>
<td colspan="3" align="middle">
<input width="100%" value="0" name="ReadOut" size="24" type="Text"/>
</td>
<td
>
<td>
<input value=" C " name="btnClear" onclick="Clear()" type="Button"/>
</td>
<td><input value=" CE " name="btnClearEntry" onclick="ClearEntry()" type="Button"/>
</td>
</td
></tr>
<tr>
<td>
<input value=" 7 " name="btnSeven" onclick="NumPressed(7)" type="Button"/>
</td>
<td>
<input value=" 8 " name="btnEight" onclick="NumPressed(8)" type="Button"/>
</td>
<td>
<input value=" 9 " name="btnNine" onclick="NumPressed(9)" type="Button"/>
</td>
<td>
</td>
<td>
<input value=" +/- " name="btnNeg" onclick="Neg()" type="Button"/>
</td>
<td>
<input value=" % " name="btnPercent" onclick="Percent()" type="Button"/>
</td>
</tr>
<tr>
<td>
<input value=" 4 " name="btnFour" onclick="NumPressed(4)" type="Button"/>
</td>
<td>
<input value=" 5 " name="btnFive" onclick="NumPressed(5)" type="Button"/>
</td>
<td>
<input value=" 6 " name="btnSix" onclick="NumPressed(6)" type="Button"/>
</td>
<td>
</td>
<td align="middle"><input value=" + " name="btnPlus" onclick="Operation('+')" type="Button"/>
</td>
<td align="middle"><input value=" - " name="btnMinus" onclick="Operation('-')" type="Button"/>
</td>
</tr>
<tr>
<td>
<input value=" 1 " name="btnOne" onclick="NumPressed(1)" type="Button"/>
</td>
<td>
<input value=" 2 " name="btnTwo" onclick="NumPressed(2)" type="Button"/>
</td>
<td>
<input value=" 3 " name="btnThree" onclick="NumPressed(3)" type="Button"/>
</td>
<td>
</td>
<td align="middle"><input value=" * " name="btnMultiply" onclick="Operation('*')" type="Button"/>
</td>
<td align="middle"><input value=" / " name="btnDivide" onclick="Operation('/')" type="Button"/>
</td>
</tr>
<tr>
<td>
<input value=" 0 " name="btnZero" onclick="NumPressed(0)" type="Button"/>
</td>
<td>
<input value=" . " name="btnDecimal" onclick="Decimal()" type="Button"/>
</td>
<td colspan="3">
</td>
<td>
<input value=" = " name="btnEquals" onclick="Operation('=')" type="Button"/>
</td>
</tr>
</table>
</b></table>

</form>
</center>
<font face="Verdana, Arial, Helvetica" size="2">
<script language="JavaScript">
<!-- Begin
var FKeyPad = document.Keypad;
var Accum = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else {
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op) {
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accum += parseFloat(Readout);
else if ( '-' == PendingOp )
Accum -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accum /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accum *= parseFloat(Readout);
else
Accum = parseFloat(Readout);
FKeyPad.ReadOut.value = Accum;
PendingOp = Op;
}
}
function Decimal () {
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear () {
Accum = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent () {
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accum);
}
// End -->
</script></font>

Hasilnya sperti dibawah ini:

























































Mudah bukan??? Dan ini akan bagus apabila Anda memasangnya di Sidebar Blog Anda.

Selamat mencoba....



11 komentar:

Popular Posts