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

  • Are you using the default magento mini cart or some other ajax mini cart.? – Athul Vijayan Jun 28 '17 at 13:17
  • @AthulVijayan default. – Rudolph Jun 28 '17 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? – Rudolph Jun 28 '17 at 14:52
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>
  • It still removes the product (the link fires anyway). – Rudolph Jun 29 '17 at 12:22
  • This is working fine on my magento instance. – Athul Vijayan Jun 30 '17 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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