title: How do you display the Total using "onClick"?
body: <p>I am wrapping up a project, and suddenly stumped. I am trying to get the "Total" to display only when "CHECKOUT" is clicked. Currently, it populates automatically. I have looked online for different functions that do just that, but I am not having any luck. Any guidance is appreciated.</p>
  
  <p>The pseudocode would look something like: onClick() return Total</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
  
    $(document).on("input paste keyup", ".product_qty", function(event) {
  
      var product_quantity = 0;
      var product_price = 0;
      var gst_amount = 0;
  
      var sub_total = 0;
      var total_qty = 0;
      var grand_total = 0
  
      product_quantity = $(this).val();
      product_price = $(this).parent().prev().html();
  
      sub_total = product_price * product_quantity;
  
      $(this).parent().next().html(sub_total);
  
  
      $('.product_qty').each(function(k, v) {
        product_quantity = parseInt($(this).val()) ? parseInt($(this).val()) : 0;
        product_price = parseFloat($(this).parent().prev().html()) ? parseFloat($(this).parent().prev().html()) : 0;
  
        console.log(product_quantity);
        console.log(product_price);
  
        sub_total = parseFloat(product_price * product_quantity);
  
        console.log(sub_total);
  
        total_qty += product_quantity;
  
        grand_total += sub_total;
  
      });
  
      if (grand_total &gt; 0) {
        gst_amount = (grand_total * 8) / 100;
      }
  
      $("#total_qty").html(total_qty);
      $("#total_amount").html(grand_total);
  
      grand_total += gst_amount;
  
      $("#gst_amount").html(gst_amount);
      $("#discount_amount").html(0);
      $("#grand_total").html(grand_total);
  
    });
    //
    $(document).on("click", ".delete", function(event) {
      var cart_item = 0;
      $(this).parent().parent().remove();
      cart_item = $('.product_qty').length;
      if (cart_item &lt;= 0) {
        $("#total_qty").html('0');
        $("#total_amount").html('0');
        $("#gst_amount").html('0');
        $("#discount_amount").html(0);
        $("#grand_total").html('0');
      } else {
        $('.product_qty').trigger('keyup');
      }
  
    });
  
  
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet" /&gt;
  &lt;link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /&gt;
  &lt;div class="bs-example"&gt;
    &lt;div class="table-responsive"&gt;
      &lt;table class="table table-bordered"&gt;
        &lt;colgroup&gt;
          &lt;col class="con1" style="align: center; width: 30%" /&gt;
          &lt;col class="con1" style="align: center; width: 20%" /&gt;
          &lt;col class="con0" style="align: center; width: 20%" /&gt;
          &lt;col class="con1" style="align: center; width: 20%" /&gt;
          &lt;col class="con1" style="align: center; width: 10%" /&gt;
        &lt;/colgroup&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;th&gt;Product&lt;/th&gt;
            &lt;th&gt;Price&lt;/th&gt;
            &lt;th&gt;Quantity&lt;/th&gt;
            &lt;th&gt;Sub Total&lt;/th&gt;
            &lt;th&gt;&amp;nbsp;&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
  
          &lt;tr&gt;
            &lt;td&gt;Mens T Shirt&lt;/td&gt;
            &lt;td class="product_price"&gt;25&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="qty" class="product_qty" value="0"&gt;&lt;/td&gt;
            &lt;td class="amount_sub_total"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href="#" class="delete"&gt;x&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;Hat&lt;/td&gt;
            &lt;td class="product_price"&gt;15&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="qty" class="product_qty" value="0"&gt;&lt;/td&gt;
            &lt;td class="amount_sub_total"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href="#" class="delete"&gt;x&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;Womens T Shirt&lt;/td&gt;
            &lt;td class="product_price"&gt;20&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="qty" class="product_qty" value="0"&gt;&lt;/td&gt;
            &lt;td class="amount_sub_total"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href="#" class="delete"&gt;x&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
            &lt;td&gt;Total&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td id="total_qty"&gt;&lt;/td&gt;
            &lt;td id="total_amount"&gt;&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;Tax (8%)&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td id="gst_amount"&gt;&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td colspan="5" class="checkout"&gt;&lt;a href="#"&gt;CHECKOUT&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;Total Payment&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td id="grand_total"&gt;&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  
          &lt;/tr&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>