Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6541219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:04:41+00:00 2026-05-25T11:04:41+00:00

I am using jQuery and ASP.NET MVC 3 with the razor view engine .

  • 0

I am using jQuery and ASP.NET MVC 3 with the razor view engine.

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.

I have the following textboxes and label (for the calculated results):

<input id="GrossMonthlySalary" type="text" />
<input id="SpouseGrossMonthlySalary" type="text" />
<input id="AdditionalIncome" type="text" />
<input id="ChildSupportIncome" type="text" />

<label id="TotalMonthlyIncome" class="total-amount"></label>

In my .js file I have the following:

$(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);
      }
   });
});

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?

Just another question on the way that I calculated the results, is this good or is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:04:41+00:00Added an answer on May 25, 2026 at 11:04 am

    Keep in mind that parseInt will fail the second it hits a non numeric character:

    parseInt('$10') // NaN
    

    As far as calculating the total, since you aren’t doing any additional processing for specific values, you could simplify the whole thing by using a class selector.

    $('.incomes').keyup(function () {
    
      var incomes = $('.incomes'),
          totalDisplay = $('#TotalMonthlyIncome'),
          totalVal = 0;
    
      incomes.each(function() {
          var matches = null;
          // find the number to add to total
          matches = $(this).val().match(/\d+/);
          // not bothering with the regex on totalVal because we set it
          totalVal = ( matches !== null ? parseInt(matches[0],10) : 0 ) + parseInt(totalVal,10);
      });
      totalVal = totalVal === 0 ? '' : totalVal;
      totalDisplay.text(totalVal);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery and ASP.NET MVC 3 with the razor view engine .
Here's the situation: ASP.NET MVC 3 application using Razor as the view engine. Works
In my ASP.net MVC App (using Razor views) I have a ProductDetails view. This
Possible Duplicate: Client Id for Property (ASP.Net MVC) In my View I'm using jquery
Using ASP.NET MVC + jQuery : I need to use some values owned by
I am using ASP.Net MVC along with Jquery to create a page which contains
I have build a webapplication using ASP.NET MVC and JQuery. On my local machine
I am using jquery on asp.net mvc. I have textbox on page and I
I have a webpage developed in ASP.NET MVC 3 and I am using jQuery
I have one question regarding using JQuery UI tab control in the asp.net mvc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.