CALCULATRICE (2)
Codes à insérer entre les balises <HEAD> et </HEAD> de votre document HTML
<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> Cliquez ici pour tout sélectionner
Codes à insérer entre les balises <BODY> et </BODY> de votre document HTML
<form name="Keypad"> <div align="center"><center><table border="0"> <tr> <td><div align="center"><center><table border="2" cellspacing="5" width="50" height="60"> <tr> <td align="middle" colspan="3"><b><input type="text" size="24" name="ReadOut" value="0" width="100%"> </b></td> <td </td> </td> <td><b><input type="button" name="btnClear" value=" C " onclick="Clear()"> </b></td> <td><b><input type="button" name="btnClearEntry" value=" CE " onclick="ClearEntry()"> </b></td> </tr> <tr> <td><b><input type="button" name="btnSeven" value=" 7 " onclick="NumPressed(7)"> </b></td> <td><b><input type="button" name="btnEight" value=" 8 " onclick="NumPressed(8)"> </b></td> <td><b><input type="button" name="btnNine" value=" 9 " onclick="NumPressed(9)"> </b></td> <td> </td> <td><b><input type="button" name="btnNeg" value=" +/- " onclick="Neg()"> </b></td> <td><b><input type="button" name="btnPercent" value=" % " onclick="Percent()"> </b></td> </tr> <tr> <td><b><input type="button" name="btnFour" value=" 4 " onclick="NumPressed(4)"> </b></td> <td><b><input type="button" name="btnFive" value=" 5 " onclick="NumPressed(5)"> </b></td> <td><b><input type="button" name="btnSix" value=" 6 " onclick="NumPressed(6)"> </b></td> <td> </td> <td align="middle"><b><input type="button" name="btnPlus" value=" + " onclick="Operation('+')"> </b></td> <td align="middle"><b><input type="button" name="btnMinus" value=" - " onclick="Operation('-')"> </b></td> </tr> <tr> <td><b><input type="button" name="btnOne" value=" 1 " onclick="NumPressed(1)"> </b></td> <td><b><input type="button" name="btnTwo" value=" 2 " onclick="NumPressed(2)"> </b></td> <td><b><input type="button" name="btnThree" value=" 3 " onclick="NumPressed(3)"> </b></td> <td> </td> <td align="middle"><b><input type="button" name="btnMultiply" value=" * " onclick="Operation('*')"> </b></td> <td align="middle"><b><input type="button" name="btnDivide" value=" / " onclick="Operation('/')"> </b></td> </tr> <tr> <td><b><input type="button" name="btnZero" value=" 0 " onclick="NumPressed(0)"> </b></td> <td><b><input type="button" name="btnDecimal" value=" . " onclick="Decimal()"> </b></td> <td colspan="3"> </td> <td><b><input type="button" name="btnEquals" value=" = " onclick="Operation('=')"> </b></td> </tr> </table> </center></div></td> </tr> </table> </center></div> </form> <font size="2" face="Verdana, Arial, Helvetica"> Cliquez ici pour tout sélectionner