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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:17:54+00:00 2026-05-30T16:17:54+00:00

table1 has contents ( items ) while table 2 has nothing ( because it

  • 0

table1 has contents ( items ) while table 2 has nothing ( because it is the shopping cart ) now what i want to do is to check if the user is adding the same item on the shopping cart and if he/she does it will add the qty and doesn’t write another tr. How can i do this?

#table 1
<table>
  <tr><td>Item001</td><td>5.00</td></tr>
  <tr><td>Item002</td><td>5.00</td></tr>
</table>

#table 2 //it is blank because it will be filled later via onclick from table1
<table>
</table>

if the user clicked item001 it will be appended to table2 now if the user selects item001 again it must not write item001 again on table2 but will only append the quantity.

UPDATE

var itemDesc = $(this).find('.desc').text();
var getPrice = $(this).find('.price').text();
var itemName = $(this).find('.itemName').text();
var currentId = $('#cartGrid tr').attr('id');

if(itemName == currentId)
{ 
    qty +=1;
    $('.tableQty').html(qty);
    qty = 1;
}
else{
    $('#cartGrid').append("<tr id="+ itemName +"><td>" + itemDesc + "</td><td class='tableQty'>"+ qty +"</td><td class='tablePrice'> $" + getPrice +"</td></tr>");
    
}

Now i got it to work. But only on the first item. Help? THank you

  • 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-30T16:17:55+00:00Added an answer on May 30, 2026 at 4:17 pm

    I modified your code a bit to get it working:

    demo: http://jsfiddle.net/qmVHr/

    // HTML

    <table class="items">
      <tr>
        <td class="name">Item001</td><td>5.00</td>
      </tr>
      <tr>
        <td class="name">Item002</td><td>5.00</td>
      </tr>
    </table>
    
    <table class="shopping-cart"></table>​​​​​​​​​​​​​​​​​
    

    // JS

    $(function() {
      $('table.items td.name').click(function() {
        var itemName = $(this).text();
        var $addedItem = $('#' + itemName);
    
        if ($addedItem.length) {
          var qty = parseInt($addedItem.find('.qty').text());
    
          $addedItem.find('.qty').text(qty + 1);
        } else {
          $('<tr id="' + itemName + '"><td>' + itemName + '</td><td class="qty">1</td></tr>').appendTo($('table.shopping-cart'));
        }
    });
    

    You didn’t post the complete code, but it seems like your problem is in this part:

    qty +=1;
    $('.tableQty').html(qty); // this will update all the rows in your shoppingcart grid, not just the one you want
    qty = 1; // not sure why you put 1 here, but this will always set the updated qty to be 1 + 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to do this : There is a table called table1 it has
i need to do this : There is a table called table1 it has
I have a simple table (lets call it Table1) that has a NVARCHAR field
I want to add table2 into the scrollpanel (called feedback) which already has table1
While my initial problem counting the running number of rows in a table has
I have a status update, and comment db table. A user has many status
Now this widget has items that should be provided by a php file. For
My application has about half a dozen different types of items that a user
My table 'Post' has field: id, name, content, post_id When i create new post,
I have 2 tables. Table1 has fields A, B, C, D and Table2 has

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.