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 7924631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:50:56+00:00 2026-06-03T17:50:56+00:00

I have a form with four text input elements. Every time one of them

  • 0

I have a form with four text input elements. Every time one of them is updated, I want the sum of the four text input boxes to be displayed in a div below without the user pushing a button. Here’s what I have so far (I got the idea from here [does this only work with select?]):

var getSum = function() {
    var email = $('#emailDown').val();
    var internet = $('#internetDown').val();
    var server = $('#serverDown').val();
    var desktop = $('#pcDown').val();
    //TODO:Check for integers (not needed with sliders)
    var sum = email + internet + server + desktop;
    $('totalHoursDown').html(sum);
}
$('#emailDown').change(getSum(event));
$('#internetDown').change(getSum(event));
$('#serverDown').change(getSum(event));
$('#pcDown').change(getSum(event));

Currently, it’s not updating. (Don’t worry about validating). I’m new to PHP, so I’m not sure if I should be using it in this instance.

  • 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-06-03T17:51:02+00:00Added an answer on June 3, 2026 at 5:51 pm

    You are missing a # or . in your selector, depending on if totalHoursDown is a class or an ID:

    $('totalHoursDown').html(sum);
    
    // Should be this if ID
    $('#totalHoursDown').html(sum);
    // or this if class
    $('.totalHoursDown').html(sum);
    

    Update:

    I modified the code by jmar777 a bit to make it work. Try this instead:

    $(function(){
        var $fields = $('#emailDown, #internetDown, #serverDown, #pcDown'),
        $totalHoursDown = $('#totalHoursDown');
        $fields.change(function() {
            var sum = 0;
            $fields.each(function() 
                     { 
                         var val = parseInt($(this).val(), 10);
                         sum += (isNaN(val)) ? 0 : val; 
                     });
            $totalHoursDown.html(sum);
        });
    });
    

    ​Here is a working fiddle as well: http://jsfiddle.net/mSqtD/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form with multiple input type=radio with text next to them. I want
I am using windows application and I have four combo boxes(comboeventname,combosendtype,comboType,comboschedule) in that form....
I have have a simple HTML form with say four input widgets (see below)...two
I have four email fields in a form, and I want that the user
I have a global form which I want to use the same form every
I have a form like this: <form action='' onsubmit='void(0)' class=mainform> <label class=form3><input type=checkbox> One
I have four input fields: MaxWidth MaxHeight and Width Height I want to validate
I have form and some fields and I want send these fields to the
I have form with few buttons and I want to know what button is
i have a small form with four EditText fields in which second EditText is

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.