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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:26:02+00:00 2026-06-04T03:26:02+00:00

I am using a system that generates a shopping cart summary in a table

  • 0

I am using a system that generates a shopping cart summary in a table with little room to customise. What I would like to do is when the shopping cart is ’empty’ display ‘0’

When it has a quantity in it, display that number.

This is the generated HTML which I have hidden:

<span vertical="False" quote="False" id="catCartSummary">
   <table cellspacing="0" class="cartSummaryTable">
     <tbody>
       <tr>
         <td class="cartSummaryItem">3 item(s), Total: $115.00 <a href="/OrderRetrievev2.aspx?CatalogueID=0" class="cartSummaryLink">View Cart</a></td>
       </tr>
     </tbody>
   </table>
</span>

As you can see it currently has “3 item(s)”.

This is what is looks like empty:

<span vertical="False" quote="False" id="catCartSummary">
   <table cellspacing="0" class="cartSummaryTable">
     <tbody>
       <tr>
         <td class="cartSummaryItem">Shopping cart is empty.</td>
       </tr>
     </tbody>
   </table>
</span>

Now I have some simple HTML setup here:

<div class="cartsummary">
  <div class="cartitems">Shopping Cart <a href="#"><span class="cartTotal"></span> Item(s)</a></div>
</div>

Using jQuery I’d like to then take the quantity and add it to .cartTotal and if there’s nothing in the cart just show 0.

This sort of works but if I add a new item to the cart it only updates the value when the page is refreshed, whereas the auto generated updates dynamically.

if (jQuery('#catCartSummary .cartSummaryItem').html() != 'Shopping cart is empty.') {
   var summary = jQuery('#catCartSummary .cartSummaryItem').text().split(" ");
   var total = summary[0];
   jQuery('span.cartTotal').html(total);
}else{
   jQuery('span.cartTotal').html("0");
}

Few extra’s worth noting:

  1. It would be great to be able to have 0 ‘Items’, 1 “item”, 2 “items”. Rather than always “Item(s)”
  2. It would be also great to separately display the total cost in another span. Perhaps .cartAmount.
  • 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-04T03:26:03+00:00Added an answer on June 4, 2026 at 3:26 am

    try:

    var text = $('#catCartSummary .cartSummaryItem').text();
    items = text.match(/(\d+) item/);
    var num = 0;
    if(items &&items.length > 0){
       num = items[1];
    }
    $(".cartItems").html('<div class="cartitems">Shopping Cart <a href="#"><span class="cartTotal">'+num+'</span> Item'+(num == 1 ? '' : 's') +'</a></div>');
    

    some pointers:

    • use .text() to not get any html in the text variable
    • use a regex to parse out the number of items instead of splitting
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an input system (using the windows messaging system) that I would
I'm creating xml-like mark-up language using System.Xml.XmTextWriter that will be read by a third
I'd like to implement a system that generates unique NxN blocks when given a
Currently, I have a system that actively generates the pages on my site using
We are using a system that allows ActiveX extensions through .ocx files. I need
I have a plug-in vector established using System.AddIn that accepts the body of a
I am using System.Reflection to load a type that I cannot otherwise load during
I am using System.IO.FIle.ReadAllText() to get the contents of some template files that I
I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
I have an interface that contains a single method called ListAll() using System.Collections.Generic; namespace

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.