title: Submitting form data without reloading page
body: <p>I am trying to submit the form without reloading the page itself using the jQuery, but the data is not showing up and the form is reloading, which is not needed.</p>
  
  <p><strong>jQuery code:</strong></p>
  
  <pre><code>function submitFormData() {
  var firstval = $("#first").val();
  var second = $("#second").val();
  //var operator = $("#myselect option:selected" ).text();
  $.post("index.php",{first:first,second:second},
  function(data){
      $('#results').html(data);
      $('#formcal')[0].reset();
  });
  }
  </code></pre>
  
  <p>THIS IS THE HTML CODE ON THE SAME PAGE(INDEX.PHP):</p>
  
  <pre><code>&lt;form action="" id="formcal" method="post"&gt;
  
  &lt;input type="number" id="first" name="first" placeholder="number"/&gt;
  &lt;select name="operator" id="operator"&gt;
  &lt;option value="add"&gt;+&lt;/option&gt;
  &lt;option value = "subtract"&gt;-&lt;/option&gt;
  &lt;option value = "multiply"&gt;*&lt;/option&gt;
  &lt;option value = "division"&gt;/&lt;/option&gt;
  
  
  &lt;/select&gt;
  &lt;input type="number" id="second" name="second" placeholder="number 2"/&gt;
  &lt;input type="button" id="submitFormData" onclick="SubmitFormData();" value="Calculate"/&gt;
  &lt;/form&gt;
  
  &lt;br&gt;
  &lt;?php //if(!empty($_POST['first']) &amp;&amp; !empty($_POST['second'])){
          $number = $_POST['first'];
          $number2 = $_POST['second'];
  
          echo "Answer:  ";
          if($_POST['operator'] == 'add'){
              $complete = $number + $number2;
              echo " $number + $number2 = $complete";
          }
          if($_POST['operator'] == 'subtract'){
              $complete = $number - $number2;
              echo "$number - $number2 = $complete";
          }
          if($_POST['operator'] == 'multiply'){
              $complete = $number * $number2;
              echo "$number X  $number2 = $complete";
          }
          if($_POST['operator'] == 'division'){
              $complete = $number / $number2;
              echo "$number / $number2 = $complete";
          }
      //} 
      ?&gt;
  &lt;/div&gt;
  
  &lt;div id="results"&gt;
  &lt;/div&gt;
  </code></pre>