title: Jquery Addition and Percentage calculation
body: <p>I am trying to calculate percentage and addition using JQuery. Addition can properly run but percentage calculation cannot. My code is below. 
  How can I change it and calculate the percentage?</p>
  
  <p>index.php </p>
  
  <pre><code>&lt;!DOCTYPE html&gt; 
   &lt;html&gt; 
   &lt;head&gt; 
   &lt;title&gt;&lt;/title&gt; 
  
   &lt;/head&gt; 
   &lt;body&gt; 
   &lt;br/&gt;&lt;br /&gt; 
  
   &lt;form id="jquery_percentage"&gt; 
   &lt;label&gt;Total Marks&lt;/label&gt; 
   &lt;input type="text" name="total_marks" id="total_marks"/&gt; 
   &lt;br/&gt; 
   &lt;br/&gt; 
   &lt;label&gt;Written Marks&lt;/label&gt; 
   &lt;input type="text" name="written_marks" id="written_marks"/&gt; 
   &lt;br/&gt; 
   &lt;br/&gt; 
   &lt;label&gt;Viva Marks&lt;/label&gt; 
   &lt;input type="text" name="viva_marks" id="viva_marks"/&gt; 
   &lt;br/&gt; 
   &lt;br/&gt; 
   &lt;label&gt;Grooming Marks&lt;/label&gt; 
   &lt;input type="text" name="grom_marks" id="grom_marks"/&gt; 
   &lt;br/&gt; 
   &lt;br/&gt; 
   &lt;label&gt;Obtain Marks&lt;/label&gt; 
   &lt;input type="text" name="obt_marks" id="obt_marks"/&gt; 
   &lt;br/&gt; 
   &lt;br/&gt; 
   &lt;label&gt;Percentage Marks&lt;/label&gt; 
   &lt;input type="text" name="perc_marks" id="perc_marks"/&gt; 
   &lt;br/&gt; 
   &lt;br/&gt; 
   &lt;input type="button" name="submit" id="submit" value="Submit" /&gt; 
   &lt;/form&gt; 
   &lt;div id="return"&gt;&lt;/div&gt; 
    &lt;/body&gt; 
   &lt;/html&gt; 
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt;&lt;/script&gt; 
   &lt;script&gt;
  
  $('#written_marks, #grom_marks, #viva_marks').change(function(){
      var written_marks = parseFloat($('#written_marks').val()) || 0;
      var grom_marks = parseFloat($('#grom_marks').val()) || 0;
      var viva_marks = parseFloat($('#viva_marks').val()) || 0;
  
      $('#obt_marks').val(written_marks + viva_marks + grom_marks);    
  });
  &lt;/script&gt;
  &lt;script&gt;
  
  $('#total_marks, #obt_marks').change(function(){
      var total_marks = parseFloat($('#total_marks').val());
      var obt_marks = parseFloat($('#grom_marks').val());
      //var viva_marks = parseFloat($('#viva_marks').val()) || 0;
  
      $('#perc_marks').val((obt_marks * 100) / total_marks);    
  });
  &lt;/script&gt;
  </code></pre>