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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:19:48+00:00 2026-06-10T21:19:48+00:00

I am using simplecart js. It’s a really simple shop with one product. I

  • 0

I am using simplecart js. It’s a really simple shop with one product. I would like to automatically redirect to the cart page when someone clicks the add to cart button.

The code for adding a product:

<div class="simpleCart_shelfItem">
<h2 class="item_name"> Awesome T-shirt </h2>
<p>  <input type="text" value="1" class="item_Quantity"><br>
<span class="item_price">$35.99</span><br>
<a class="item_add" href="javascript:;"> Add to Cart </a></p>
</div>

The listener in simpleCart.js:

/* here is our shelfItem add to cart button listener */
                , { selector: 'shelfItem .item_add'
                    , event: 'click'
                    , callback: function () {
                        var $button = simpleCart.$(this),
                            fields = {};

                        $button.closest("." + namespace + "_shelfItem").descendants().each(function (x,item) {
                            var $item = simpleCart.$(item);

                            // check to see if the class matches the item_[fieldname] pattern
                            if ($item.attr("class") &&
                                $item.attr("class").match(/item_.+/) &&
                                !$item.attr('class').match(/item_add/)) {

                                // find the class name
                                simpleCart.each($item.attr('class').split(' '), function (klass) {
                                    var attr,
                                        val,
                                        type;

                                    // get the value or text depending on the tagName
                                    if (klass.match(/item_.+/)) {
                                        attr = klass.split("_")[1];
                                        val = "";
                                        switch($item.tag().toLowerCase()) {
                                            case "input":
                                            case "textarea":
                                            case "select":
                                                type = $item.attr("type");
                                                if (!type || ((type.toLowerCase() === "checkbox" || type.toLowerCase() === "radio") && $item.attr("checked")) || type.toLowerCase() === "text") {
                                                    val = $item.val();
                                                }               
                                                break;
                                            case "img":
                                                val = $item.attr('src');
                                                break;
                                            default:
                                                val = $item.text();
                                                break;
                                        }

                                        if (val !== null && val !== "") {
                                            fields[attr.toLowerCase()] = fields[attr.toLowerCase()] ? fields[attr.toLowerCase()] + ", " +  val : val;
                                        }
                                    }
                                });
                            }
                        });

                        // add the item
                        simpleCart.add(fields);
                    }
                }
            ]);
        });

From what I have read it is bad practice to use href=”javascript:;” is it a good idea to change it to a click function that will add the item to the cart then go to the cart page or just add the redirect? How do I go about this? Thanks

  • 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-10T21:19:50+00:00Added an answer on June 10, 2026 at 9:19 pm

    I’m not sure how the simplecart APi works, but you can try something like:

    // add the item
    simpleCart.add(fields);
    window.location='/cart/'; // change to your cart route
    

    If the cart saves to a server cookie, you might need to put this in a callback.

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

Sidebar

Related Questions

Im using simpleCart.js to build a simple, low-trafic, low product count, shopping cart. It's
I'm using the js cart simpleCart but am having a simple issue.. I have
I am using simpleCart js. I would like to have the checkout button and
Using Rails 3.2.0 with haml and sass: I Would like to link an external
Using Jenkins or Hudson I would like to create a pipeline of builds with
Using the opencart image manager how would I set the upload to automatically remove:
I'm using simpleCart.js to setup a cart on the website. The problem is the
I am building a simple cart for a friend and using an array in
I'm using simpleCart(js) to integrate shopping cart into my WordPress site. I am selling
I am using SimpleCart Js and am wondering would it be possible to make

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.