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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:05:50+00:00 2026-05-23T21:05:50+00:00

Consider the following HTML table: <table id=myTable1> <tr id=TR1> <td><input type=text id=quantity1 name=quantity1 /></td>

  • 0

Consider the following HTML table:

<table id="myTable1">
    <tr id="TR1">
        <td><input type="text" id="quantity1" name="quantity1" /></td>
        <td><input type="text" id="weight1" name="weight1" /></td>
        <td><input type="text" id="sub_total1" name="sub_total1" /></td>
    </tr>
</table>

What i’m trying to accomplish here is that I need to update the value for the sub_total field on every row based on the values typed in the quantity and weight fields on the same row every time keyup() is triggered.

Now I believe this would be a much manageable task if the table I’m working on is static only. But the inclusion of the dynamic adding of table rows caused me troubles.


JQuery for dynamic addition of rows:

$(document).ready(function() {

var counter = 2;

$("#addButton").click(function() {

    $('#myTable1 tr:last').after(
        '<tr id="TR"><td><input type="text" name="quantity' + counter + 
            '" id="quantity' + counter + '" value=""></input></td>' +

        '<td><input type="text" name="weight' + counter + 
            '" id="weight' + counter + '" value=""></input></td>' +

        '<td><input type="text" name="sub_total' + counter + 
            '" id="sub_total' + counter + '" value=""></input></td></tr>'
    );

    counter++;
});
});

Here we have the formula to be used in computing for the sub_total:

var sub_total  = ((170 * first 10 kilos) + (70 * the remaining weight)) * (quantity);

So given the sample values:
quantity = 10
weight = 15
, we should have

var sub_total  = ((170 * 10) + (70 * 5)) * (10);

I have the following as a start but ‘ not quite sure what to place inside these functions

$('#myTable1 input[id^=\'quantity\'], #myTable1 input[id^=\'weight\']').live('keyup',function() {

    $('#myTable1 input[id^=\'quantity\'], #myTable1 input[id^=\'weight\']').each(function(index, value) {
    });
});
  • 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-23T21:05:51+00:00Added an answer on May 23, 2026 at 9:05 pm

    You can use closest() to match the parent table row of the modified element. From there, it’s easier to locate the quantity, weight and sub_total elements:

    $("#myTable1 [id^=quantity], #myTable1 [id^=weight]").live("keyup", function() {
        var $tr = $(this).closest("tr");
        var quantity = parseInt($("[id^=quantity]", $tr).val());
        var weight = parseInt($("[id^=weight]", $tr).val());
    
        var firstTen;
        if (weight <= 10) {
            firstTen = weight;
            weight = 0;
        } else {
            firstTen = 10;
            weight -= 10;
        }
    
        $("[id^=sub_total]", $tr).val((170 * firstTen + 70 * weight) * quantity);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following HTML: <input type='text' id='name'/> <option id='option'> <select value='1'>hi</select> <select value='2'>bye</select>
Please consider the following HTML: <td> Some Text <table>.....</table> </td> I need to manipulate
Consider the following code : HTML: <input type='checkbox' /> <div>Click here</div> JS: $(function() {
Let's consider following html code: <p> Some text followed by <span>a span element</span> and
Consider the following HTML: <div class=foo id=obj> I should be changed red <div class=bar
Consider the following HTML snippet. The desired effect is to have a dropdown be
Consider the following HTML. If I have a JSON reference to the <button> element,
Consider the following simple html page markup: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
Consider the following: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en
Consider the following HTML and CSS. The desired result is the two pink boxes

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.