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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:47:35+00:00 2026-05-24T20:47:35+00:00

I have an HTML table with input elements that I am using for batch

  • 0

I have an HTML table with input elements that I am using for batch editing. I have constructed a skelton html example below. Could someone please help me figure out how to do something like the following:

  • add a selector to each of the “Quantity” fields, e.g. .change()
  • get the value in the Quantity and Amount fields, e.g. .val()
  • update the Total field, e.g. .text()

The main challenge is that the HTML is generated by my View in my ASP.Net MVC application, and the naming convention for the input id is “objectName_indexNumber_propertName” — e.g. MyObject_1_Quantity.

Would I just do a for-loop / .each(), and then do string manimpulation to get the id and do my magic? Is there a better way? Thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="jquery-1.4.4.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            // how do I select all of them?
            $('#MyObject_1_Quantity').change(DoCalculation);
        });

        function DoCalculation() {
            alert("what should I do here? I need to know the index/row I'm in, and which cell triggered me.");

        }
    </script>

</head>
<body>

    <p>Test jquery Selector</p>
    <table>
        <tr>
            <td>Row 1</td>
            <td><input type="text" id="MyObject_1_Quantity" /></td>
            <td><input type="text" id="MyObject_1_Rate" /></td>
            <td><span id="MyObject_1_Total">$100.00</span></td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td><input type="text" id="MyObject_2_Quantity" /></td>
            <td><input type="text" id="MyObject_2_Rate" /></td>
            <td><span id="MyObject_2_Total">$100.00</span></td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td><input type="text" id="MyObject_3_Quantity" /></td>
            <td><input type="text" id="MyObject_3_Rate" /></td>
            <td><span id="MyObject_3_Total">$100.00</span></td>
        </tr>            
    </table>

</body>
</html>
  • 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-24T20:47:35+00:00Added an answer on May 24, 2026 at 8:47 pm

    This places a handler on the 2nd <td> in each row. Then this in the handler will be that input, so you can get the nested input and the adjacent cells to to the calculation, and set the value in the <span>.

    Example: http://jsfiddle.net/Skjbv/1/

    $(document).ready(function() {
        $('table tr td:nth-child(2)').change(DoCalculation);
    });
    
    function DoCalculation() {
        var row = this.parentNode;
        input1 = this.firstChild.value;
        input2 = row.cells[2].firstChild.value;
        span =   row.cells[3].firstChild;
    
         // convert to Number----v----------v
        span.innerHTML = ('$' + (~~input1 * ~~input2).toFixed(2));
         // create string with 2 decimal places-----------^
    
    }
    

    If it isn’t quite so consistent that you can rely on the 2nd cell, then you could change the DOM selection to this, which places the handler directly on the input:

    Example: http://jsfiddle.net/Skjbv/3/

    $(document).ready(function() {
        $('table tr td input[id$="_Quantity"]').change(DoCalculation);
    });
    
    function DoCalculation() {
        var row = $(this).closest('tr');
        input1 = this.value;
        input2 = row.find('input[id$="_Rate"]').val();
        span = row.find('span[id$="_Total"]');
    
        span.html('$' + (~~input1 * ~~input2).toFixed(2));
    }
    

    These use the attribute-ends-with-selector[docs] to select the elements with the proper value at the end of the ID attribute.

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

Sidebar

Related Questions

I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>
I have an HTML table that looks like this: ------------------------------------------------- |Column 1 |Column 2
I have a very specific html table construct that seems to reveal a Gecko
I have to build an HTML table that shows data for users versus pages
This one is weird, I have a page that consists of a html table
I have a HTML file that has code similar to the following. <table> <tr>
I have an html table <table border=0 width=100%> <tr class=headerbg> <th width=5%> No </th>
I have an html table which i bind data dynamically on the server side
I have an HTML table with several columns and I need to implement a
I have snippets of Html stored in a table. Not entire pages, no tags

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.