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

  • Home
  • SEARCH
  • 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 8078063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:40:17+00:00 2026-06-05T15:40:17+00:00

I have a simple HTML Form with one column having a select menu with

  • 0

I have a simple HTML Form with one column having a select menu with 2 options: Moderate or High. I need to find all rows where the cell = “Moderate” and count the total of another cell in the same row, and repeat this for all rows where the cell = “High”. Here’s a JS Fiddle showing a sample completed table:

http://jsfiddle.net/8hn2H/

In this example the result for Total Moderate would be 1.6 and the result for Total High would be 8.7 (it’s totalling the value in the Average Hours/Week column). The number of rows will not be fixed in advance – there could be 1 or more.

Here’s the actual html for the form:

<div class="span8"><br>
      <table id="activities" class="table table-bordered table-striped">
        <thead>
          <tr>
            <th>Activity</th>
            <th>Risk</th>
            <th>Hours/Week</th>
            <th>Weeks/Year</th>
            <th>Average Hours/Week</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><input name="Activity"  id="Activity" type="text" value=""/></td>
            <td><div class="controls">
              <select id="Risk">
                <option></option>
                <option>Moderate</option>
                <option>High</option>
              </select>
            </div></td>
            <td><input class="span1" id="A1" type="text" value=""/></td>
            <td><input class="span1" id="B1" type="text" value=""/></td>
            <td><input class="span1" id="C1" type="text" value=""/></td>
            <td><button class="btn">Delete Activity</button></td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>Total Moderate</td>
            <td></td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>Total High</td>
            <td></td>
          </tr>
        </tbody>
      </table>
    </div>
  • 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-05T15:40:19+00:00Added an answer on June 5, 2026 at 3:40 pm
    var moderateTotal = 0;
    var highTotal = 0;
    $("#activities").find("tr").each(function() {
        var tr = $(this);
        var level = tr.find("td:nth-child(2)").html();
        var value = tr.find("td:nth-child(5)").html();
    
        switch(level)
        {
            case "Moderate":
                moderateTotal += value*1;
            break;
            case "High":
                highTotal += value*1;
            break;
        }
    });
    
    $("#activities tr:last td:last").prev().html("High Total: " + highTotal);
    $("#activities tr:last").prev().find("td:last").prev().html("Moderate Total: " + moderateTotal);
    

    I use jQuery’s .find() and .each() function to iterate over each row. I use find again to find the level and value (2nd and 5th columns) and a switch statement to add the value to the totals. I need to do value*1 to convert the string to an integer so it will add. Default behavior here is concatenate.

    The last two lines set the value of the table cells. It’d be a lot easier if you could just give those a specific ID so you can just do $("moderateTotal").html() but since that wasn’t given I used some jQuery selectors to do it.

    Demo

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

Sidebar

Related Questions

I have a simple HTML form which starts with a select menu where the
This is probably a basic html/css question... I have a simple one-button form that
I have got a simple HTMl form with one field as follows: <input type=text
I have a form, which at the moment is a simple HTML based one,
I have a simple html form. On php page. A simple list is placed
I have a simple HTML form. I'd like the right widgets in the second
I have a simple html form that is structured something like this: <form name=test
I am getting a strange behavior for multi-part form. I have a simple HTML
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have a simple situation here. lets face html code first => <form name=geoKey

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.