I am working on a shopping website and want to check if the item is present in the cart. If it exists, alert it's already in the cart and return false
. If it doesn't exist add it to the cart.
I tried it like below, the code is working fine but the alert is looping.
$("#showBtn").focus();
msgBoxImagePath = "http://www.ournestonline.com/assets/images/";
function showMsgBox() {
simpleCart.bind('beforeAdd', function (item) {
if (simpleCart.has(item)) {
alert("Already in the Cart");
$.msgBox({
title: "Shopping Cart",
content: "Already in cart",
type: "alert"
});
return false;
} else {
$.msgBox({
title: "Shopping Cart",
content: "Great Selection Your Item is Added to Cart Happy Shopping",
type: "alert"
});
}
});
}