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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:55:35+00:00 2026-05-19T23:55:35+00:00

I am trying to add the option fields on a row to the total

  • 0

I am trying to add the option fields on a row to the total field on the row, using jquery. I can’t use ids because there are a variable number of rows, that get created with clone as the user needs them.

<tr>
<td><input name="option_1[]" type="text" class="integer add_to_total"  /></td>
<td><input name="option_2[]" type="text" class="numeric add_to_total"/> </td>
<td><input name="option_3[]" type="text" class="numeric add_to_total"/> </td>
<td><input name="total[]" type="text"   class="numeric is_total"  /> </td>
</tr>

I thought of attaching a change event to the input fields with the ‘add_to_total’ class and using the sibling function to add to the ‘is_total’ class. but I can’t get that syntax right:

$(".add_to_total").change(function() {
    var line_total = 0;
    line_total += $(this + " .add_to_total").siblings().val();
    $(this +  " .is_total").siblings().val(line_total);
});

I get syntax errors and it doesn't work.
  • 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-19T23:55:35+00:00Added an answer on May 19, 2026 at 11:55 pm
    $('.add_to_total').change(function(){
      var total = 0;
      var row = $(this).closest('tr');
      row.find('.add_to_total').each(function(){
        total += this.value.replace(/[^\d\.-]/,'')*1;
      });
      row.find('.is_total').val( total );
    });
    

    The replace() allows the user to enter 1,000 and not have you end up with NaN for your total.

    If speed is a big concern, I might suggest caching the row.find('.add_to_total') as jQuery data on the row, but that’s an optimization best left until you’re sure you need it.

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

Sidebar

Related Questions

I am trying to add a row to my Model and have that option
I'm trying add a tab to my web page that looks like this: Using
Trying to add the ability to delete a Folder using FTP and all subfolders
Trying to add an onclick handler to my tabs, and can't seem to get
Trying to add a class object into a List using reflection, but when invoking
For an Android application, I'm trying to use a Spinner which, when an option
I am trying to add multiple values to a hidden field. It's working fine,
I'm trying to add content to something before an item using the CSS :before
Can someone please help me with this conditional field validation in CodeIgniter? Trying to
I'm trying to follow Microsoft's example on how to add an All option to

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.