title: Troubles with javascript calculator functions not being called
body: <p>Note: the problem seems to be mainly caused by the program being unable to call the functions correctly, as changing them to just be 'alert()' made them all work fine.</p>
  
  <p>I recently wanted to make a calculator on an html page using javascript, which was going fine until I noticed that after I finished, the buttons didn't actually do anything. After some troubleshooting (that's why the alert()s are in the functions, I figured out that my functions weren't being correctly called. I'm not quite sure what I'm doing wrong, so I need some help. Here's the code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;
  Web calculator
  &lt;/title&gt;
  &lt;script language="JavaScript"&gt;
  &lt;!--
  var num1="", num2="", operation="", solution=0;
  
  function clear(){
      alert()
      window.document.calculator.display.value="CLEAR";
      window.document.calculator.display.size=5;
      operation="";
      solution=0;
      num1="";
      num2="";
  }
  function addNumber(number){
      alert();
      window.document.calculator.display.value+=number;
      window.document.calculator.display.size+=1;
      if(operation.length&gt;0){
          num2+=number;
      }
      else if(operation.length==0){
          num1+=number;
      };
  }
  function addOperation(op){
      alert()
      operation=op;
      var value = window.document.calculator.display.value;
      if((parseInt(value.indexOf('+')) + parseInt(value.indexOf('-')) + parseInt(value.indexOf('/')) + parseInt(value.indexOf('*')))!=-4){
          window.document.calculator.display.size+=1;
          window.document.calculator.display.value+=operation;
      else{
          window.document.calculator.display.value-="-";
          window.document.calculator.display.value-="+";
          window.document.calculator.display.value-="/";
          window.document.calculator.display.value-="*";
          window.document.calculator.display.value=num1+operation+num2;
      };
  }
  function solve(){
      alert()
      num1=num1.parseFloat(num1);
      num2=num2.parseFloat(num2);
      switch(operation){
          ('+'){
              solution=num1+num2;
          }
          ('-'){
              solution=num1-num2;
          }
          ('*'){
              solution=num1*num2;
          }
          ('/'){
              solution=num1/num2;
          }
      };
      window.document.calculator.display.value=solution;
  }
  --&gt;
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onLoad="clear();"&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
  &lt;center&gt;
  &lt;form name="calculator"&gt;
      &lt;table border=5&gt;
          &lt;tr&gt;
              &lt;center&gt;
              &lt;td colspan=3&gt;
                  &lt;input type="text" name="display" readonly value="" size="5"&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="button" name="buttonclear" readonly value="C" onClick="clear();"&gt;
              &lt;/td&gt;
              &lt;/center&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;center&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonseven" readonly value="7" onClick="addNumber('7');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttoneight" readonly value="8" onClick="addNumber('8');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonnine" readonly value="9" onClick="addNumber('9' /*this part is fixed due to a below comment, however it was not the culprit of the problem*/);"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonminus" readonly value="-" onClick="addOperation('-');"&gt;
              &lt;/td&gt;
              &lt;/center&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;center&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonfour" readonly value="4" onClick="addNumber('4');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonfive" readonly value="5" onClick="addNumber('5');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonsix" readonly value="6" onClick="addNumber('6');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonplus" readonly value="+" onClick="addOperation('+');"&gt;
              &lt;/td&gt;
              &lt;/center&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;center&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonone" readonly value="1" onClick="addNumber('1');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttontwo" readonly value="2" onClick="addNumber('2');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonthree" readonly value="3" onClick="addNumber('3');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttontimes" readonly value="*" onClick="addOperation('*');"&gt;
              &lt;/td&gt;
              &lt;/center&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;center&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttondot" readonly value="." onClick="addNumber('.');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonzero" readonly value="0" onClick="addNumber('0');"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttonequals" readonly value="=" onClick="solve();"&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;input type="button" name="buttondivide" readonly value="/" onClick="addOperation('/');"&gt;
              &lt;/td&gt;
              &lt;/center&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>