title: Retaining calculated jQuery totals after postback
body: <p>I am using <code>jQuery</code> and <code>ASP.NET MVC 3</code> with the <code>razor view engine</code>.</p>
  
  <p>I have a couple of textboxes in which numeric values can be typed.  I have a label control that has the totals of the textboxes calculated by jQuery.</p>
  
  <p>I have the following textboxes and label (for the calculated results):</p>
  
  <pre><code>&lt;input id="GrossMonthlySalary" type="text" /&gt;
  &lt;input id="SpouseGrossMonthlySalary" type="text" /&gt;
  &lt;input id="AdditionalIncome" type="text" /&gt;
  &lt;input id="ChildSupportIncome" type="text" /&gt;
  
  &lt;label id="TotalMonthlyIncome" class="total-amount"&gt;&lt;/label&gt;
  </code></pre>
  
  <p>In my .js file I have the following:</p>
  
  <pre><code>$(function () {
  
     $('#GrossMonthlySalary, #SpouseGrossMonthlySalary, #AdditionalIncome, #ChildSupportIncome').keyup(function () {
        var val1 = $('#GrossMonthlySalary').val();
        var val2 = $('#SpouseGrossMonthlySalary').val();
        var val3 = $('#AdditionalIncome').val();
        var val4 = $('#ChildSupportIncome').val();
  
        var totalMonthlyIncome =
           (parseInt(val1, 10) || 0) +
           (parseInt(val2, 10) || 0) +
           (parseInt(val3, 10) || 0) +
           (parseInt(val4, 10) || 0);
  
        if (totalMonthlyIncome == 0) {
           $('#TotalMonthlyIncome').text('');
        }
        else {
           $('#TotalMonthlyIncome').text(totalMonthlyIncome);
        }
     });
  });
  </code></pre>
  
  <p>If I click on my submit button and there are errors then the errors are displayed and the my label control with the calculated results are cleared.  How do I retain the values after post back?</p>
  
  <p>Just another question on the way that I calculated the results, is this good or is there a better way?</p>