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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:34:48+00:00 2026-06-08T20:34:48+00:00

I’m using simplecart.js to build a small store on a website I created before.

  • 0

I’m using simplecart.js to build a small store on a website I created before. I have one problem. The whole shopping cart is displayed with only one line of code:

<div class="simpleCart_items"></div>

And the javascript prints the table, you can’t see it in the source code. BUT, inspect element in chrome is a good friend of mine, and the table created will look something like this:

<table>
    <tbody>
        <tr class="headerRow">
            <th class="item-name">Tuote</th>
            <th class="item-price">Hinta</th>
            <th class="item-decrement"></th>
            <th class="item-quantity">Määrä</th>
            <th class="item-increment"></th>
            <th class="item-total">Yhteensä</th>
            <th class="item-remove"></th>
        </tr>
        <tr class="itemRow row-0 odd" id="cartItem_SCI-3">
            <td class="item-name">Teipit (Valkoinen hiilikuitu)</td>
            <td class="item-price">€48.00</td>
            <td class="item-decrement">
                <a href="javascript:;" class="simpleCart_decrement">-</a>
            </td>
            <td class="item-quantity">1</td>
            <td class="item-increment">
                <a href="javascript:;" class="simpleCart_increment">+</a>
            </td>
            <td class="item-total">€48.00</td>
            <td class="item-remove">
                <a href="javascript:;" class="simpleCart_remove">Poista</a>
            </td>
        </tr>
    </tbody>
</table>

And I want it to print something like this:

<table>
    <tbody>
        <tr class="headerRow">
            <th class="item-name">Tuote</th>
            <th class="item-price">Hinta</th>
            <th class="item-decrement"></th>
            <th class="item-quantity">Määrä</th>
            <th class="item-increment"></th>
            <th class="item-total">Yhteensä</th>
            <th class="item-remove"></th>
        </tr>
        <tr class="itemRow row-0 odd" id="cartItem_SCI-3">
            <td class="item-name">Teipit (Valkoinen hiilikuitu)</td>
            <td class="item-price">€48.00</td>
            <td class="item-decrement">
                <a href="javascript:;" class="simpleCart_decrement">-</a>
            </td>
            <td class="item-quantity">1</td>
            <td class="item-increment">
                <a href="javascript:;" class="simpleCart_increment">+</a>
            </td>
            <td class="item-total">€48.00</td>
            <td class="item-remove">
                <a href="javascript:;" class="simpleCart_remove">Poista</a>
            </td>
        </tr>
        <tr class="shippingtotal" id="shipping">
            <td class="item-name">Shipping</td>
            <td class="shipping-cost">€5.00</td>
            <td class="item-decrement">
                <a href="javascript:;" class="simpleCart_decrement">-</a>
            </td>
            <td class="item-quantity">1</td>
            <td class="item-increment">
                <a href="javascript:;" class="simpleCart_increment">+</a>
            </td>
            <td class="item-total">€48.00</td>
            <td class="item-remove">
                <a href="javascript:;" class="simpleCart_remove">Poista</a>
            </td>
        </tr>
    </tbody>
</table>

So, here’s the simplecart.js itself:
http://pastebin.com/j5VKGkV1

I think that I should add something to this part of the code:

// write out cart
                writeCart: function (selector) {
                    var TABLE = settings.cartStyle.toLowerCase(),
                        isTable = TABLE === 'table',
                        TR = isTable ? "tr" : "div",
                        TH = isTable ? 'th' : 'div',
                        TD = isTable ? 'td' : 'div',
                        cart_container = simpleCart.$create(TABLE),
                        header_container = simpleCart.$create(TR).addClass('headerRow'),
                        container = simpleCart.$(selector),
                        column,
                        klass,
                        label,
                        x,
                        xlen;

                    container.html(' ').append(cart_container);

                    cart_container.append(header_container);


                    // create header
                    for (x = 0, xlen = settings.cartColumns.length; x < xlen; x += 1) {
                        column = cartColumn(settings.cartColumns[x]);
                        klass = "item-" + (column.attr || column.view || column.label || column.text || "cell") + " " + column.className;
                        label = column.label || "";

                        // append the header cell
                        header_container.append(
                        simpleCart.$create(TH).addClass(klass).html(label));
                    }

                    // cycle through the items
                    simpleCart.each(function (item, y) {
                        simpleCart.createCartRow(item, y, TR, TD, cart_container);
                    });

                    return cart_container;
                },

                // generate a cart row from an item
                createCartRow: function (item, y, TR, TD, container) {
                    var row = simpleCart.$create(TR).addClass('itemRow row-' + y + " " + (y % 2 ? "even" : "odd")).attr('id', "cartItem_" + item.id()),
                        j,
                        jlen,
                        column,
                        klass,
                        content,
                        cell;

                    container.append(row);

                    // cycle through the columns to create each cell for the item
                    for (j = 0, jlen = settings.cartColumns.length; j < jlen; j += 1) {
                        column = cartColumn(settings.cartColumns[j]);
                        klass = "item-" + (column.attr || (isString(column.view) ? column.view : column.label || column.text || "cell")) + " " + column.className;
                        content = cartCellView(item, column);
                        cell = simpleCart.$create(TD).addClass(klass).html(content);

                        row.append(cell);
                    }
                    return row;
                }

            });

But what? the shipping can be displayed with this:
<span class="simpleCart_shipping"></span> I’ve tried adding that after the cart, but it looks kind of silly.

Update: This is an example without the mofication (before):
Before
And this is what it should be like..

What I need

  • 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-08T20:34:50+00:00Added an answer on June 8, 2026 at 8:34 pm

    Start off by adding this:

        // [..]
        header_container = simpleCart.$create(TR).addClass('headerRow'),
    
        // Added line
        total_container = simpleCart.$create(TR).addClass('shippingtotal').attr('id', "shipping" ),
    
        container = simpleCart.$(selector),
        // [..]
    

    And

        // create header
        // [..]
    
        // cycle through the items
        // [..]
    
        // create total
        cart_container.append(total_container);
        total_container.append( createTotalShippingRow() );   // Even though invoked just once
    
        return cart_container;
    

    And

    createCartRow: function (item, y, TR, TD, container) {
        // [..]
    },
    
    createCartTotalShippingRow: function() {
    
        // Impl. look other update
    }
    
    createTotalShippingRow: function() {
    
        // Impl. look other update
    }
    

    I’ll work on the impl. now 🙂

    Add the following to your settings.. (from http://pastebin.com/j5VKGkV1)

    settings = {
    
        cartTotalColumns: [{
            attr: "name",
            label: "Name"
        }, {
            attr: "price",
            label: "Price",
            view: 'currency'
        }, {
            view: "empty",      // replaces decrement
            label: false
        }, {
            attr: "empty",      // replaces quantity
            label: false        // Qty
        }, {
            view: "empty",      // replaces increment
            label: false
        }, {
            attr: "total",
            label: "SubTotal",
            view: 'currency'
        }, {
            view: "empty",      // replaces remove
    //      text: "Remove",
            label: false
        }],
    }
    

    Update [..]
    [..removed code from update..]
    Try to write reusable code (you want similair output for items & total).
    Try to let the methods do what they describe they do (appending outside container, you returned the row anyways).
    Try to use proper variable names.
    Try to seperate different kinds of functionality.
    Even in the writeCart method, you could split ‘createHeader(..) createItems(..) createTotal(..)’.

    Further, try to use semantic names. At least the ‘y’ variable should be renamed as ‘rowIndex’ or something.

    Update:

    createTotalShippingRow: function( TR, TD ) {
    
        // I think we shouldn't instantiate the item here, but you could test if this works?
        var item = {
            name: "Shipping",
            price: 5,               
    //      view: "empty",      // decrement
    //      attr: "empty",      // quantity
    //      view: "empty",      // increment
            total: this.total(),
    //      view: "empty",      // remove
            };
    
        var rowid = "shipping";
    
        return createCartTotalShippingRow( item, rowid, TR, TD );
    },
    
    createCartTotalShippingRow: function( item, rowclass, rowid, TR, TD ) {
        var row = simpleCart.$create(TR).addClass( rowclass ).attr( 'id', rowid ),
            i = 0,
            cartTotalColumns = settings.cartTotalColumns,
            ln = cartTotalColumns.length,
            column,
            classname;
    
        for ( ; i < ln; i++ ) {
            column = cartColumn( cartTotalColumns[ i ] );
            classname = "item-" + ( column.attr || ( isString( column.view ) ? column.view : column.label || column.text || "cell" ) ) + " " + column.className;
            content = cartCellView( item, column );
            cell = simpleCart.$create(TD).addClass(classname).html(content);
            row.append(cell);
        }
    
        return row;
    }
    

    UPDATE:

    whole file.. But I have the same error as I had with your original code (the method create doesn’t exist). But that has nothing to do with your request by itself.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.