Warning: Creating default object from empty value in /home/thescrip/public_html/jclass/load_globes.php on line 22

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/thescrip/public_html/jclass/load_globes.php:22) in /home/thescrip/public_html/jincludes/globals.php on line 43

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/thescrip/public_html/jclass/load_globes.php:22) in /home/thescrip/public_html/jincludes/globals.php on line 43

Warning: Creating default object from empty value in /home/thescrip/public_html/jclass/load_globes.php on line 22

Warning: Creating default object from empty value in /home/thescrip/public_html/jclass/db_func.php on line 61

Warning: Creating default object from empty value in /home/thescrip/public_html/jclass/db_func.php on line 61

Warning: Creating default object from empty value in /home/thescrip/public_html/jclass/db_func.php on line 61
JavaScript Windows like calculator
TheScriptCenter.com


print page

Windows like Calculator

Works just like a windows calculator. I wrote this script a long time ago just for the heck of it. The first program I ever wrote in college was a Calculator in VB and I don't think I ever got it working so maybe that's why I decided to write this one. Use it for what ever you'd like. 

Calculator
 
 
 
 
 
Code: <form name=mef>
<input type=hidden name=dafunction value="">
<input type=hidden name=tempnum value="">
<input type=hidden name=daboo value="">
<input type=hidden name=memob value="0">
  <script language=javascript>
  <!--//
  //script written by Jason J. Russo
  //more free scripts: http://thescriptcenter.com
   
  function numbers(x) {
   
  var daboo= document.mef.daboo.value;
  var dafunction = document.mef.dafunction.value;
  var deccheck = document.mef.results.value;
  if(document.mef.results.value == "0" && deccheck.indexOf('.')=="-1") {
  document.mef.results.value = "";
  }
   
  if(daboo != "true") {
  document.mef.results.value=document.mef.results.value+x;
  } else {
  document.mef.results.value=x;
  document.mef.daboo.value="";
  }
   
  }
   
  function add() {
  if(document.mef.tempnum.value){
  gofigure();
  }
   
  document.mef.dafunction.value='+';
  document.mef.daboo.value='true';
  document.mef.tempnum.value=document.mef.results.value;
  }
   
  function subtract() {
   
  if(document.mef.tempnum.value){
  gofigure();
  }
  document.mef.dafunction.value='-';
  document.mef.daboo.value='true';
  document.mef.tempnum.value=document.mef.results.value;
  }
   
  function multiply() {
  if(document.mef.tempnum.value){
  gofigure();
  }
  document.mef.dafunction.value='*';
  document.mef.daboo.value='true';
  document.mef.tempnum.value=document.mef.results.value;
  }
  function divide() {
   
  if(document.mef.tempnum.value){
  gofigure();
  }
  document.mef.dafunction.value='/';
  document.mef.daboo.value='true';
  document.mef.tempnum.value=document.mef.results.value;
  }
   
  function oneoverx() {
  document.mef.results.value=1/eval(document.mef.results.value);
  }
   
  function percenta() {
  var whatdo = document.mef.dafunction.value;
  var percnumber = document.mef.results.value / 100;
  if(document.mef.tempnum.value){
  document.mef.results.value = eval(document.mef.tempnum.value)*percnumber;
  } else {
  document.mef.results.value = "0";
  }
  document.mef.tempnum.value="";
  document.mef.dafunction.value="";
  }
   
  function squaroot() {
  document.mef.results.value=Math.sqrt(document.mef.results.value);
  }
  function plusminus() {
  var xy = document.mef.results.value;
  if(xy == "0"){
  return false;
  }
  if(xy.indexOf("-") == "0") {
  xy = xy.substring(1,xy.length);
   
  } else {
  xy = "-" + xy;
   
  }
  document.mef.results.value = xy;
  }
  function backspace() {
  //ignore if zero already.//
  if(document.mef.results.value=="0") {
  return false; }
  //length of the text field//
  var numlength = document.mef.results.value;
  //subtract one.//
  var newresult = numlength.length-1;
  //set to new value -1;//
  document.mef.results.value = numlength.substring(0,newresult);
  //set to zero if nothing left.
  if(document.mef.results.value=="") {document.mef.results.value ="0";}
  }
   
  function clearfu() {
  document.mef.tempnum.value="";
  document.mef.results.value="0";
  document.mef.dafunction.value="";
  }
   
  function gofigure() {
  if(document.mef.tempnum.value==".") {
  return false;
  }
  var whatdo = document.mef.dafunction.value;
  if(whatdo=="+"){
  document.mef.results.value = eval(document.mef.results.value) + eval(document.mef.tempnum.value);
  }
  else if(whatdo=="-"){
  document.mef.results.value = eval(document.mef.tempnum.value)-eval(document.mef.results.value);
  }
  else if(whatdo=="*"){
  document.mef.results.value = eval(document.mef.results.value) * eval(document.mef.tempnum.value);
  }
   
  else if(whatdo=="/"){
  document.mef.results.value = eval(document.mef.tempnum.value)/eval(document.mef.results.value) ;
  }
   
  document.mef.tempnum.value="";
  document.mef.dafunction.value="";
  }
  //-->
  </script>
  <table style="border-style:inset;border-width:2px;" bgcolor=#CCCCCC><tr>
  <td><font face=verdana color=white><B>Calculator</b></td></tr><tr>
  <td><input type=text value="0" size=33 name=results></td>
  </tr>
  <tr><td>
  <input type=text name=memry style="background-color:#CCCCCC;" size=2>
  <input type=button value="Backspace" style="background-color:#CCCCCC;color:red;width:67px;height:27px;font-size:10px;" OnClick="backspace()"> <input type=button value="CE" style="background-color:#CCCCCC;color:red;width:67px;height:27px;font-size:10px;" OnClick="clearfu()"> <input type=button value=" C " style="background-color:#CCCCCC;color:red;width:57px;height:27px;font-size:10px;" OnClick="clearfu()">
  </td></tr><tr>
  <td>
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value="MC" OnClick="document.mef.memry.value=' ',document.mef.memob.value='0'"> &nbsp;
  <input type=button value="7" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(7)"> <input type=button value="8" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(8)"> <input type=button value="9" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(9)">
   
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value="/" OnClick="divide()">
  <input type=button style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" value="sqrt" OnClick="squaroot()">
  </td></tr><tr>
  <td>
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value="MR" OnClick="document.mef.results.value=document.mef.memob.value"> &nbsp;
  <input type=button value="4" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(4)"> <input type=button value="5" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(5)"> <input type=button value="6" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(6)">
   
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value="*" OnClick="multiply()">
  <input type=button style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" value="%" OnClick="percenta()">
  </td></tr>
  <tr>
  <td>
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value="MS"> &nbsp;
  <input type=button value="1" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(1)"> <input type=button value="2" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(2)"> <input type=button value="3" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(3)">
   
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value=" - " OnClick="subtract()">
  <input type=button style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" value=" 1/x " OnClick="oneoverx()">
  </td>
  </tr><tr>
  <td>
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value=" M+ " OnClick="document.mef.memry.value=' M',document.mef.memob.value=document.mef.results.value;"> &nbsp;
  <input type=button value="0" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers(0)"> <input type=button value="+/-" style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="plusminus() "> <input type=button value="." style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" OnClick="numbers('.')">
   
  <input type=button style="background-color:#CCCCCC;color:red;width:35px;height:27px;font-size:10px;" value="+" OnClick="add()">
  <input type=button style="background-color:#CCCCCC;color:blue;width:35px;height:27px;font-size:10px;" value="=" OnClick="gofigure()">
  </td></tr>
  <tr><td> </td></tr>
  </table>
  </form>