»
EnglishFrenchVietnamese

Print - Better Calculator - JavaScriptBank.com

Full version: jsB@nk » Calculation » Calculator » Better Calculator
URL: https://www.javascriptbank.com/better-calculator.html

Better Calculator © JavaScriptBank.comA calculator code with memory screen, built-in help screens, and new window function.

Full version: jsB@nk » Calculation » Calculator » Better Calculator
URL: https://www.javascriptbank.com/better-calculator.html



JavaScript
<script type="text/javascript"><!-- Begin/*Created by: Jim Anderson :: http://bettercalculator.comBetterCalculator v1.2  Copyright 2001(C) *//* You will need to create another file with the same codecalled 'BetterCalc.htm' to use to create the new window. */function open_Calc(mypage,myname,w,h,features) {  var winl = (screen.width-w)/1.05;  var wint = (screen.height-h)/1.55;  if (winl < 0) winl = 0;  if (wint < 0) wint = 0;  var settings = 'height=' + h + ',';  settings += 'width=' + w + ',';  settings += 'top=' + wint + ',';  settings += 'left=' + winl + ',';  settings += features;  win = window.open(mypage,myname,settings);  win.window.focus();}function what(dir) {if (event.button == 2) { Help(dir) }}function Help(dir) {  var ex;  if (dir == 'eq') { ex = ' = : Equals\n\n Calculates the result of an equation.' }  else if (dir == '/') { ex = ' ?: Division\n\n Divides one number by another.\n\n\ i.e.: 8 / 2 = 4' }  else if (dir == 'x') { ex = ' x : Multiplication\n\n Multiplies two numbers.\n\n\ i.e.: 2 x 4 = 8' }  else if (dir == '+') { ex = ' + : Addition\n\n Adds two numbers together.\n\n\ i.e.: 3 + 4 = 7' }  else if (dir == '-') { ex = ' - : Subtraction\n\n Subtracts one number from another.\n\n\ i.e.: 7 - 4 = 3' }  else if (dir == '%') { ex = ' % : Percent\n\n Displays the percentage of a number.\n\n\tTo find the percentage of one number in relation to another,\n\tenter the first number, hit the X key, enter a second number,\n\thit the % key.\n\n\tex: 40 x 10% = 4' }  else if (dir == '.') { ex = ' . : Decimal\n\n Adds a decimal point to a number in DISPLAY screen.' }  else if (dir == '1') { ex = ' 1 : Number 1\n\n Places the number 1 onto DISPLAY screen.' }  else if (dir == '2') { ex = ' 2 : Number 2\n\n Places the number 2 onto DISPLAY screen.' }  else if (dir == '3') { ex = ' 3 : Number 3\n\n Places the number 3 onto DISPLAY screen.' }  else if (dir == '4') { ex = ' 4 : Number 4\n\n Places the number 4 onto DISPLAY screen.' }  else if (dir == '5') { ex = ' 5 : Number 5\n\n Places the number 5 onto DISPLAY screen.' }  else if (dir == '6') { ex = ' 6 : Number 6\n\n Places the number 6 onto DISPLAY screen.' }  else if (dir == '7') { ex = ' 7 : Number 7\n\n Places the number 7 onto DISPLAY screen.' }  else if (dir == '8') { ex = ' 8 : Number 8\n\n Places the number 8 onto DISPLAY screen.' }  else if (dir == '9') { ex = ' 9 : Number 9\n\n Places the number 9 onto DISPLAY screen.' }  else if (dir == '0') { ex = ' 0 : Zero\n\n Places the numerical value 0 onto DISPLAY screen.' }  else if (dir == 'DZ') { ex = ' 00 : Double Zero\n\n Adds two zeros to any number.' }  else if (dir == 'c') { ex = ' C : Clear\n\n Clears the DISPLAY screen\n Remember to clear after each calculation.' }  else if (dir == 'Del') { ex = ' Del : Delete\n\n Clears the last digit entered.' }  else if (dir == 'M') { ex = ' M : Memory \n\n Copies number in DISPLAY screen to MEMORY.' }  else if (dir == 'RM') { ex = ' RM : Recall Memory\n\n Recalls number stored in MEMORY and places it onto\n the DISPLAY screen..' }  else if (dir == 'M+') { ex = ' M+ : Memory Add\n\n Adds number in DISPLAY screen to MEMORY.' }  else if (dir == 'M-') { ex = ' M- : Memory Subtract\n\n Subtracts number in DISPLAY screen  from MEMORY.' }  else if (dir == 'MC') { ex = ' MC : Memory Clear \n\n Clears number stored in MEMORY.' }  else if (dir == 'NW') { ex = ' New Window : \n\n Opens a popup window containing a new CALCULATOR.\n\nMultiple CALCULATORS can be open at the same time. This is useful in comparing different scenarios of calculations.\n\n\NOTE: If you have a popup stopper on your system, you will need to disable it to view the NEW WINDOW.' }  else if (dir == 'H') { ex = 'BetterCalculator 1.2 is freeware Javascript. You may save the code to your computer or Web site as long as you do not change anything.\n\nRight click on any button for a description and help with that function. Left click to push a  button or key.\n\n\For instructions on how to add this Calculator to your desktop and info on more advanced versions of BetterCalculator featuring 2 manipulative MEMORY screens, a copy/printable  RECORD screen, plus much more. Go to http://BetterCalculator.com \n\n\Thank you\n\n\Jim Anderson \n'}alert(ex);}// End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<script type="text/javascript"><!-- Beginvar mem = '0';function calc() {  document.calculator.display.value= eval(document.calculator.display.value);  return true}function perc() {  document.calculator.display.value= eval(document.calculator.display.value)/100;  return true}function deleteChar() {  document.calculator.display.value = document.calculator.display.value.substring(0, document.calculator.display.value.length - 1)}function Clear() {  currentoperation=""; }// End --></script><table align=center width="20%" cellpadding="1" bgcolor="#999999" border="2" bordercolordark="#333399" bordercolorlight="#0033FF"><td valign=top align=center><table style="border: 1px solid ivory"><form name="calculator"><td><center><font face="Verdana, Helvetica, Sans-serif"><a href="http://www.bettercalculator.com" target=_blank><font color="#ffffff" size= "1">BetterCalculator 1.2</font></a></td></tr><tr><td><input style="font-size: 12px;color=000000;background=cccccc;" type="text" value="" name="display" value="input" size="24"><br></td></tr></table><table bgcolor="#8b8b83" border="1" bordercolordark="#EEEEE0" bordercolorlight="#FFFFF0"><tr><td><input style="font-size:12pt; height: 24px; width: 24px"  type="button" value="7"style="cursor:pointer;cursor:hand"onmousedown=what('7');onmouseup="calculator.display.value+='7';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="8"style="cursor:pointer;cursor:hand"onmousedown=what('8');onmouseup="calculator.display.value+='8';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="9"style="cursor:pointer;cursor:hand"onmousedown=what('9');onmouseup="calculator.display.value+='9';" ></td><td><input style="font-size:13pt; height: 24px; width: 38px;color=ffffff;background=999999;" type="button" value="x"style="cursor:pointer;cursor:hand"onmousedown=what('x');onclick="calculator.display.value+='*';"></td></tr><tr><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="4"style="cursor:pointer;cursor:hand"onmousedown=what('4');onmouseup="calculator.display.value+='4';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="5"style="cursor:pointer;cursor:hand"onmousedown=what('5');onmouseup="calculator.display.value+='5';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="6"style="cursor:pointer;cursor:hand"onmousedown=what('6');onmouseup="calculator.display.value+='6';"></td><td><input style="font-size:14pt; height: 24px; width: 38px;color=ffffff;background=999999;" type="button" value="¡Â"style="cursor:pointer;cursor:hand"onmousedown=what('/');onclick="calculator.display.value+='/';"></td></tr><tr><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="1"style="cursor:pointer;cursor:hand"onmousedown=what('1');onmouseup="calculator.display.value+='1';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="2"style="cursor:pointer;cursor:hand"onmousedown=what('2');onmouseup="calculator.display.value+='2';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="3"style="cursor:pointer;cursor:hand"onmousedown=what('3');onmouseup="calculator.display.value+='3';"></td><td><input style="font-size:14pt; height: 24px; width: 38px;color=ffffff;background=999999;" type="button" value="-"style="cursor:pointer;cursor:hand"onmousedown=what('-');onclick="calculator.display.value+='-';"></td></tr><tr><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="0"style="cursor:pointer;cursor:hand"onmousedown=what('0');onmouseup="calculator.display.value+='0';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="00"style="cursor:pointer;cursor:hand"onmousedown=what('DZ');onmouseup="calculator.display.value+='00';"></td><td><input style="font-size:12pt; height: 24px; width: 24px" type="button" value="•"style="cursor:pointer;cursor:hand"onmousedown=what('.');onclick="calculator.display.value+='.';"></td><td><input style="font-size:14pt; height: 24px; width: 38px;color=ffffff;background=999999;" type="button" value="+"style="cursor:pointer;cursor:hand"onmousedown=what('+');onclick="calculator.display.value+='+';"></td></tr><tr><td><input style="font-size:10pt; height: 24px; width: 24px;color=ffffff;background=999999;" type="button" value="%"style="cursor:pointer;cursor:hand"onmousedown=what('%');onclick="perc()"></td><td><input style="font-size:7pt; height: 24px; width: 24px;color=ffffff;background=999999;" type="button" value="Del"style="cursor:pointer;cursor:hand"onmousedown=what('Del');onmouseup="deleteChar(calculator.display.value)"></td><td><input style="font-size:12pt; height: 24px; width: 24px;color=000000;background=eead0e;" type="button" value="C"style="cursor:pointer;cursor:hand"onmousedown=what('c');onclick="calculator.display.value='';"></td><td><input style="font-size:14pt; height: 24px; width: 38px;color=ffffff;background=999999;" type="button" value="="style="cursor:pointer;cursor:hand"onmousedown=what('eq');onclick="calc()"></td></tr></table><center><table width="20%" cellpadding="0" bgcolor="#228B22" border="1"><td><input style="font-size:9pt; height: 20px; width: 20px;color=ffffff;background=228B22;" type="button" value="M"style="cursor:pointer;cursor:hand"onmousedown=what('M');onclick="mem.value=calculator.display.value;"></td><td><input style="font-size:9pt; height: 20px; width: 22px;color=ffffff;background=228B22;" type="button" value="M+"style="cursor:pointer;cursor:hand"onmousedown=what('M+');onmouseup="mem.value=eval(mem.value)+eval(calculator.display.value);"></td><td><input style="font-size:9pt; height: 20px; width: 21px;color=ffffff;background=228B22;" type="button" value="M-"style="cursor:pointer;cursor:hand"onmousedown=what('M-');onmouseup="mem.value=eval(mem.value)-eval(calculator.display.value);"></td><td><input style="font-size:9pt; height: 20px; width: 25px;color=ffffff;background=228B22;" type="button" value="MR"style="cursor:pointer;cursor:hand"onmousedown=what('MR');onclick="calculator.display.value=calculator.display.value+'('+(mem.value)+')'"></td><td><input style="font-size:9pt; height: 20px; width: 25px;color=000000;background=eead0e;" type="button" value="MC"style="cursor:pointer;cursor:hand"onmousedown=what('MC');onclick="mem.value='0';"></td></tr></table><center><TABLE BORDER=0><form name="mem"><table><td valign=top align=center><font size=2 color=000000><input style="font-size: 12px;color=000000;background=cccccc;" type="text" value="0" name="mem" size="22"></font></td></tr></table><p align=center><input style="font-size:6pt; height: 19px; width: 34px;color=ffffff;background=8b658b;" type="button" value="Help"style="cursor:help"onmousedown=what('H');onclick="alert('BetterCalculator 1.2 is freeware Javascript. You may save the code to your computer or Web site as long as you do not change anything.\n\nRight click on any button for a description and help with that function (Internet Explorer only). Left click to push a  button or key.\n\n\For instructions on how to add this Calculator to your desktop and info on more advanced versions of BetterCalculator featuring 2 manipulative MEMORY screens, a copy/printable  RECORD screen, plus much more. Go to http://BetterCalculator.com \n\n\Thank you\n\n\Jim Anderson \n');">  <input style="font-size:6pt; height: 19px; width: 54px;color=ffffff;background=8b658b;" type="button" value="Window"style="cursor:pointer;cursor:hand"onmousedown=what('NW');onclick="open_Calc('BetterCalc.htm','','170','344','')"></form></table><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->