0

The add to cart button is not working on my product page, the following error shows up in the console:

Uncaught TypeError: Cannot read property 'submit' of undefined at HTMLButtonElement.onclick 

This is the code on the add to basket button -

<button type="button" title="Add to Basket" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span>Add to Basket</span></span></button>

Having had a look I think I may have found the reason that it is not adding to cart. The form which the button submits has a different id to the actual form. Is this the reason for not submitting? And if so, how do I change this?

<form action="https://cbccomputers.com/checkout/cart/add/uenc/aHR0cHM6Ly9jYmNjb21wdXRlcnMuY29tL3Bjcy1sYXB0b3BzLXRhYmxldHMvY29tcHV0ZXJzL3Bjcy9kZWxsLXZvc3Ryby0zMjY4LWkzLmh0bWw_X19fU0lEPVU,/product/61297/form_key/Qj8R0mDVuAViFpbP/" method="post" id="product_addtocart_form">

Relatively new to Magento and developing so any advice is helpful as it is quite urgent?

Thanks.

1 Answer 1

2

change code from the original

<button type="button" title="Add to Basket" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span>Add to Basket</span></span></button>

to

<button type="submit" title="Add to Basket" class="button btn-cart" ><span><span>Add to Basket</span></span></button>
12
  • Yes you need to change code in app\design\frontend\themefolder\template\catalog\product\view.phtml Jul 13, 2017 at 10:12
  • themefolder means your theme path in your site Jul 13, 2017 at 10:21
  • Hi, yes I am in the view.phtml file I was just wondering which bit of the code I change once I am in the view.phtml as I don't know PHP. Thanks
    – user55794
    Jul 13, 2017 at 10:23
  • stackoverflow.com/questions/24273443/… visit this and enalble template path hint. Jul 13, 2017 at 10:24
  • after this path where you have to change code is there Jul 13, 2017 at 10:25

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.