title: PHP Make a simple calculator - Code doesnt work
body: <p>I am trying to make a simple calculator like this :</p>
  
  <p>input1 select input2 = input3</p>
  
  <ul>
  <li>input1,input2 is first and second value</li>
  <li>select have 4 operator : + - * /</li>
  <li>input3 show the result</li>
  </ul>
  
  <p>This is my code and it doesnt work as expected,can someone help me out ?</p>
  
  <pre><code>&lt;?php
  ini_set('display_errors', 0);
  session_start();
  
  /*  Check if form is submit 
   *  if any input field is empty --&gt; "NaN" result
   *  else check value of select field --&gt; do the math --&gt; result
   *  Then call JS function to change value of result field
   */ 
  
  if(isset($_GET['act']) &amp;&amp; $_GET['act']== 'do')  {
  
      $val1 = $_GET['val1'];
      $val2 = $_GET['val2'];
      $oper = $_GET['oper'];
  if($val1 == NULL || $val2 == NULL)  
      $result= "NaN";
  else    {
      switch($oper)   {
          case 1 : $result= $val1 + $val2; break;
          case 2 : $result= $va1l - $val2; break;
          case 3 : $result= $val1 * $val2; break;
          case 4 : $result= $val1 / $val2; break;
      }
  }
  echo "&lt;script&gt; showResult('".$result."') &lt;/script&gt;";
  }
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;style&gt;
  input,select { height:30px;width:50px}
  
  &lt;/style&gt;
  
  
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form method="GET" action="bai4_1.php?act=do"&gt;
      &lt;table&gt;
      &lt;tr&gt;&lt;td&gt;Op1&lt;/td&gt;
          &lt;td&gt;Oper&lt;/td&gt;
          &lt;td&gt;Op2&lt;/td&gt;
          &lt;td&gt;Result&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;&lt;input id="val1" type="text" name="val1" value="&lt;?php echo 
  $_GET['val1'];?&gt;"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;select id="oper" name="oper"&gt;
              &lt;option value=1&gt;+&lt;/option&gt;
              &lt;option value=2&gt;-&lt;/option&gt;
              &lt;option value=3&gt;*&lt;/option&gt;
              &lt;option value=4&gt;/&lt;/option&gt;
              &lt;/select&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input id="val2" type="text" name="val2" value="&lt;?php 
  echo$_GET['val2'];?&gt;"/&gt; =&lt;/td&gt;         
          &lt;td&gt;&lt;input id="result" type="text"&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
  &lt;script&gt;
  $("input,select").change(function(){
  setTimeout(function(){
      $("form").submit();
  },1000);
  });
  
  function showResult(result) {
  $("#result").val(result);
  }   
  &lt;/script&gt;
  </code></pre>