title: JavaScript keyup and onload to calculate a field total
body: <p>I am calculating two text inputs using JavaScript. It works with keyup. Ie when typing, the balance calculates in realtime. However, I want the total to calculate and display not only on keyup, but onload as well, so for when I load the page, that it calculates the fields already.</p>
  
  <p>This is my current working javascript code for keyup only</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).on("keyup", function() {
  var sum = 0;
  $(".totalCal").each(function(){
      sum += +$(this).val();
  });
  $("#total").val(sum);
  
  document.getElementById('grandTotal').innerHTML = sum.toFixed(2);
  });
  &lt;/script&gt;
  </code></pre>