0

here the error (from dev tools) when clicking on the Add to Cart button :

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

Changes I made (but several days before the problem appeared where activing an SSL and upgrading to Magento 1.9.3.6)

Here the code from the file addtocart.phtml:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<div class="qty-wrapper">
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo 
$this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" 
class="input-text qty" />
</div>
<?php endif; ?>
<button type="button" title="<?php echo $buttonTitle ?>" id="product-
addtocart-button" class="button btn-cart" 
onclick="productAddToCartForm.submit(this)"><span><span><?php echo 
$buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
<?php endif; ?>
  • Check your <form> tags on the page. Make sure the form tag is closed properly and encapsulates the block that contains the addtocart phtml. – seanbreeden Nov 5 '17 at 11:59
  • Hello could you clarify me where I should make this verify? Really thanks – D Consulting Nov 6 '17 at 8:31
  • Go to the product page and View Page Source. Look for your <form> and </form> tags related to adding the product to cart. Ensure that both tags exist and that the addtocart output is between them somewhere on the page. – seanbreeden Nov 6 '17 at 12:17
  • @DConsulting Did you solve your issue? – zus Jul 20 '18 at 7:05
-1
" id="product- addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"> getChildHtml('', true, true) ?>

change to button type to submit

" id="product- addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"> getChildHtml('', true, true) ?>
  • I don't think changing the button type will make any difference. All the sites I have use type="button" – jscar Nov 7 '17 at 9:05

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.