title: Calculator with Javascript
body: <p>I am a beginner and trying to write a simple Calculator in Javascript but something is wrong.</p>
  
  <p>When the user enters numbers, "Number 1" and "Number 2", then the following should occur for addition, subtraction, multiply and division (for example):</p>
  
  <pre><code>Number1 = 5, Number2 = 3
  then   =&gt; 5 + 3 = 8,
            5 - 3 = 2,
            5 * 3 = 15,
            5 / 3 = 1.6
  </code></pre>
  
  <p>When the user gives numbers to specific equation, then displays the result of these operations.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Function Calculator&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
     function show_cal(){
      function num(){
      a=Number(document.form1.num1.value);  
      b=Number(document.form1.num2.value); 
      c=a+b;
      document.form1.result1.value=c;
  
      a=Number(document.form1.num1.value);  
      b=Number(document.form1.num2.value); 
      c=a-b;
      document.form1.result2.value=c;
  
      a=Number(document.form1.num1.value);  
      b=Number(document.form1.num2.value); 
      c=a*b;
      document.form1.result3.value=c;
  
      a=Number(document.form1.num1.value);  
      b=Number(document.form1.num2.value); 
      c=a/b;
      document.form1.result4.value=c;
      }
  
      function addition(){
      a=Number(document.form1.num3.value);  
      b=Number(document.form1.num4.value); 
      c=a+b;
      document.form1.result1.value=c;
      }
  
      function subtraction(){
      a=Number(document.form1.num5.value);  
      b=Number(document.form1.num6.value); 
      c=a-b;
      document.form1.result2.value=c;
      }
  
      function multiply(){
      a=Number(document.form1.num7.value);  
      b=Number(document.form1.num8.value); 
      c=a*b;
      document.form1.result3.value=c;
      }
  
      function division(){
      a=Number(document.form1.num9.value);  
      b=Number(document.form1.num10.value); 
      c=a/b;
      document.form1.result4.value=c;
      }
  
      /*function formValidator(){
      var number = document.getElementById('number');
          if(isNumeric(number, "Only Numbers pls")){
          return true;
          }return false;
      }
  
      function notEmpty(elem, helperMsg){ //gia keno
          if(elem.value.length == 0){
              alert(helperMsg);
              elem.focus(); // set the focus to this input
          return false;
          }
      return true;
      }
  
      function show_clear(){
          document.form1.display.value=null;
          num1= null;
          num2 = null;
          lastaction= null;
          action = null;
      } */
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;table width="400" align="center" bgcolor="#C0C0C0"&gt;
      &lt;form name="form1" action=""&gt;
  
      &lt;tr align="center"&gt;
      &lt;td width="600" height="112" align="center" border="1"&gt;
          &lt;h1 align="center"&gt; Calculator &lt;/h1&gt;
      Number 1: &lt;input name="num1" type="text" size=10/&gt;
      Number 2: &lt;input name="num2" type="text" size=10/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr align="center"&gt;
      &lt;td width="500"&gt;
      &lt;input name="num3" type="text" size=10/&gt; + 
      &lt;input name="num4" type="text" size=10/&gt; =
      &lt;input name="result1" type="text" size=10/&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;br/&gt;
      &lt;tr align="center"&gt;
      &lt;td width="500"&gt;
      &lt;input name="num5" type="text" size=10/&gt; -
      &lt;input name="num6" type="text" size=10/&gt; =
      &lt;input name="result2" type="text" size=10/&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;br/&gt;
      &lt;tr align="center"&gt;
      &lt;td width="500"&gt;
      &lt;input name="num7" type="text" size=10/&gt; *
      &lt;input name="num8" type="text" size=10/&gt; =
      &lt;input name="result3" type="text" size=10/&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;br/&gt;
      &lt;tr align="center"&gt;
      &lt;td width="500"&gt;
      &lt;input name="num9" type="text" size=10/&gt; /
      &lt;input name="num10" type="text"size=10/&gt; =
      &lt;input name="result4" type="text" size=10/&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
  
  
          &lt;br/&gt;
      &lt;td height="13"&gt;&lt;/tr&gt;
      &lt;tr align="center" width="100"&gt;
      &lt;td&gt;
      &lt;input name="result" type="button" onClick="show_cal()" value="Result" /&gt;
      &lt;input type="button" onClick="show_clear()" value="Clear"/&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;/form&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>