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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:14:48+00:00 2026-06-17T09:14:48+00:00

I am trying to replace a div tag that is the same on each

  • 0

I am trying to replace a div tag that is the same on each row of a dynamically created table. I’m not sure how to go about it. Right now I can get the function to work but it only replaces the first row of div tags. Here is my code:

<script type="text/javascript">
function Calc() {
    var qty = 0;
     qty=parseInt(document.getElementById('qtyEntry').value);
    var weight = parseInt(document.getElementById('weight').innerHTML);
    var cube = parseInt(document.getElementById('cube').innerHTML);
    var carton = parseInt(document.getElementById('carton').innerHTML);

     var newWeight = 0;
     var newCube = 0;
     var newCarton = 0;

    newWeight = qty *weight ;
    newCube = qty * cube;
    newCarton = qty * carton;

     document.getElementById('weight').innerHTML = newWeight;
     document.getElementById('cube').innerHTML = newCube;
     document.getElementById('carton').innerHTML = newCarton;
}

  @{int seq=0;
               foreach (var item in Model)
               {
                   seq++;
                <tr>
                  <td>@seq</td>
                    <td>@item.sku</td>
                    <td>@item.description</td>
                    <td><input type=text id="qtyEntry" name="buildQty" size="3" onchange="Calc()"/></td>
                    <td> <div id="carton">@item.cartonQty</div></td>
                    <td> <div id="weight">@item.weight</div></td>
                    <td><div id="cube">@item.cube</div></td>
                    <td></td>
                </tr>

                }
            }

So essentially I want to update the carton, weight and cube quantities when a user changes the text field for buildQty. I want each row to update. Right now only the first row updates even if I am updating the text on another row.

  • 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-17T09:14:48+00:00Added an answer on June 17, 2026 at 9:14 am

    Glaring issue: id‘s are meant to be unique. Yours are not. So it only accesses the first one. Try this as a change:

    markup:

    <tr>
                  <td>@seq</td>
                    <td>@item.sku</td>
                    <td>@item.description</td>
                    <td><input type=text id="qtyEntry@(seq)" name="buildQty@(seq)" size="3" onchange="Calc(@(seq))"/></td>
                    <td> <div id="carton@(seq)">@item.cartonQty</div></td>
                    <td> <div id="weight@(seq)">@item.weight</div></td>
                    <td> <div id="cube@(seq)">@item.cube</div></td>
                    <td></td>
    </tr>
    

    js:

    function Calc(seq) {
     var qty = 0;
     qty=parseInt(document.getElementById('qtyEntry'+seq).value);
     var weight = parseInt(document.getElementById('weight'+seq).innerHTML);
     var cube = parseInt(document.getElementById('cube'+seq).innerHTML);
     var carton = parseInt(document.getElementById('carton'+seq).innerHTML);
    
     var newWeight = 0;
     var newCube = 0;
     var newCarton = 0;
    
     newWeight = qty *weight ;
     newCube = qty * cube;
     newCarton = qty * carton;
    
     document.getElementById('weight'+seq).innerHTML = newWeight;
     document.getElementById('cube'+seq).innerHTML = newCube;
     document.getElementById('carton'+seq).innerHTML = newCarton;
    }
    

    But note! This could possibly change your model binding and you will need to revisit the way you are going to accept this from your post. I would assume it is not properly posting as it is right now because the name is also not unique (and that is part which has to do with model binding).

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

Sidebar

Related Questions

I'm trying to replace a div with created elements, going from: <div id='links'></div> to
I'm trying to replace certain text inside the div info when an image (which
I'm trying to use GreaseMonkey to replace the background image of a DIV on
So apparently I'm trying to do something that jQuery does not like. I'm using
I have a string that represents an html document. I'm trying to replace text
I'm trying to replace all periods with the degree symbol. Using the each method
I am trying to replace some div text automatically using the .html command in
I am trying to replace a certain div element parent with another one newparent
I'm trying replace HTML5 Canvas to simple <div> But I don't know how to
I am trying to replace my radio circles by div's. The selecting by clicking

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.