0

When I click to remove product from mini-cart a confirm dialog pops up with "Cancel" or "Ok", if I click on "Cancel" the product still gets removed.

Any idea why and how to fix it?

This is the a element to remove product from mini-cart:

<a href="long_delete_url_here" title="Remove This Item" onclick="return confirm('Are you sure you would like to remove this item from the shopping cart?');" class="btn-remove">Remove This Item</a>

No errors in console, tried adding custom jquery function, adding preventDefault, but nothing. Even just adding onclick="return false;" doesn't do anything.

I did a small test and added onclick="return false;" to different elements like buttons and links in different templates, but the buttons and links still work after clicking on them. Any idea what could be wrong?

Magento 1.9.0.1

3
  • Are you using the default magento mini cart or some other ajax mini cart.? Jun 28, 2017 at 13:17
  • @AthulVijayan default.
    – rits
    Jun 28, 2017 at 14:44
  • @AthulVijayan I did a small test and added onclick="return false;" to different elements like buttons and links in different templates, but the buttons and links still work after clicking on them. Any idea what could be wrong?
    – rits
    Jun 28, 2017 at 14:52

1 Answer 1

2

Try this

  <a href="http://www.google.com" title="Remove This Item" onclick="productcartremove(event);" class="btn-remove">Remove This Item</a>


<script>

        function productcartremove(event,url) {
        var r = confirm("Are you sure you would like to remove this item from the shopping cart?");
        if (r == true) {
            return true;
        }
        else{
            event.preventDefault();
        }
    }

</script>
2
  • It still removes the product (the link fires anyway).
    – rits
    Jun 29, 2017 at 12:22
  • This is working fine on my magento instance. Jun 30, 2017 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.