Bethfiander
Bethfiander

Reputation: 177

Trying to add link into event click in js - Simplecart

I am working on a shopping cart project, and I am using simplecart framework. I am a complete beginner at javascript.

The html:

<a class="item_add" href="javascript:;">Add to Cart</a>

Basically I would like the href to go to a checkout page for example checkout.html, but the href already has "javascript:;" value for the add the cart function, is there a way of adding to the below that it redirects or directs to checkout.html after adding to cart, I have tried a few things with no avail.

The Js:

{ selector: 'shelfItem .item_add'
, event: 'click'
, callback: function () {
var $button = simpleCart.$(this),
fields = {};
... if statements
}
// add the item
simpleCart.add(fields);
}

So after the simpleCart.add(fields); is there a way to make it go to another page.

Any help would be great!

Thanks!

Upvotes: 0

Views: 267

Answers (2)

KoalaGangsta
KoalaGangsta

Reputation: 556

If you're completly done and you think you can safely start a redirect, you can easily do it by changing the href property like this:

window.location.href = 'http://your-url.com';

This will start a redirect to your-url.com but might also cut off scripts which are not finished yet.

Upvotes: 1

Dekel
Dekel

Reputation: 62616

You can use the afterAdd event for that:

simpleCart.bind( "afterAdd" , function(){
    window.location.href = 'checkout.html'
});

Upvotes: 1

Related Questions