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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:36:58+00:00 2026-06-02T18:36:58+00:00

The issue I’m having is fairly hard for me to explain, but I have

  • 0

The issue I’m having is fairly hard for me to explain, but I have replicated it in a jsFiddle http://jsfiddle.net/6ms4T/1/

What I am trying to achieve is by updating the ‘Quantity’ text box, I want to display the value elsewhere (the line below which I’ll refer to as the ‘Cost line’).

Basically, updating the first input box (qty_item_1) is updating all the (quant_) IDs in the ‘Cost line’, rather than just the one related to that product.

function recalc(){

$("[id^=quant_]").text($("input[id^=qty_item_]").val());

etc…

Full code is here: http://jsfiddle.net/6ms4T/1/

Any help would be appreciated.

  • 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-02T18:37:00+00:00Added an answer on June 2, 2026 at 6:37 pm

    You can find the id of the element that is changing and then extract the digits part of it for use in the rest of your calculations. Here is the aspects that I changed and a working version.:

    var uniqueOne = $(this).attr("id").match(/\d+/);
    $("[id^=quant_][id$="+uniqueOne+"]").text($("input[id^=qty_item_][id$="+uniqueOne+"]").val());
    

    While not the cleanest looking code, what it does is find the ids that start with quant_ and end with uniqueOne. You could probably condense these but it highlights combining two selectors (the starts with and ends with).

    Looks like you have lots of great ideas to choose from.

    Edit:

    If your id’s don’t start with qty_item_, then you’ll need to use a different selector. The lowest-hanging-fruit for this one would be the contains selector: id*=blah.

    Updated version with ‘gross’ ids to find: http://jsfiddle.net/6ms4T/22/

    Edit:

    The previous jsfiddle didn’t handle updating the total as expected. This updated version should reduce confusion by identifying all the cases where DOM elements are sought by ID; however, there is a high probability that this should be refactored: http://jsfiddle.net/6ms4T/24/.

    EDIT:

    OP’s tags had various numbers and letters generated into his IDs but the final digits were preceded by an underscore. The significant id was thereby found with the regex /\d+$/. As other posters have shown, there is more than one way to solve this. I personally liked User gabitzish’s.

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

Sidebar

Related Questions

ISSUE: I have an asp.net mvc 3 app. I'm using EF 4.1 and trying
Issue - We have a spreadsheet with thousands of addresses but no counties. Goal
ISSUE I am trying to submit an asp.net mvc form and I get the
Issue: I am using the Microsoft.Office.Interop.Excel library in an ASP.NET application, and I have
Issue with StringBuilder I have used the table tag in sb.append but it is
Issue encountered in .net framework 4.0 I have 2 dropdownlist currently with one for
My issue is that I'm trying to mock BluetoothDevice for some testing, but it's
// issue with the following not returning info or just stalling... but no errors
Issue with rendering of nested lists: I have a class: public MyRecord { String
Issue: An issue exists whereby I cannot access my Self Hosted ADO.NET Data Services

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.