SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: sum items

  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sum items

    I've tried searching for this but keep getting results on append(), etc.

    I'm building a cart that adds items via jQuery. Basically you select the product and click the 'add to cart' button and then it gets added to the page via append. Very simple.

    What I'm trying to do is total up the dollar amounts of each item added to the cart, but I can't figure out how to do that. How do I keep a running tally of prices throughout my different functions?

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,285
    Mentioned
    181 Post(s)
    Tagged
    4 Thread(s)
    Whenever I am facing a problem like this my approach is to think "how would I do it manually?"

    Afterall, computers are only useful for performing simple tasks (we can do ourselves) at a very fast rate.

    In this case, I would expect that when I am viewing my cart (all the goods I have assembled to buy) the total would be available. And so, it seems the time to devise a total is [only] when you are displaying the entire cart of items. In that view/page which displays the cart you can add the individual prices (and calculate tax, shipping, etc).
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, should have been more clear. The products and the cart are all on the same page, so I have to update the total as each item is added.

  4. #4
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Resolved. Using PHP and $.get(). Calculating the totals in a PHP SESSION and loading into the div when adding to the cart. It's amazing what some sleep will do.

    Code:
    $.get('lib/order_totals.php', function(data) {
        $('#totals').html(data);
    });


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •