3

I am using magento 1.8.1. I am using magento 1.8.1 and i changed the increment decrements scripts. with the change of there design.

jQuery(function() {

    jQuery("div.add-to-cart .qty_pan").append('<div class="inc add">&#8250;</div><div class="dec add">&#8249;</div>');

    jQuery("#plus, #minus").click(function(){
      
        var jQueryadd = jQuery(this);
        var oldValue = jQueryadd.parent().find("input").val();
  var newVal = 0;
    
        if (jQueryadd.text() == "+") {
        newVal = parseFloat(oldValue) + 1;
       // AJAX save would go here
     } else {
       // Don't allow decrementing below zero
       if (oldValue > 1) {
           newVal = parseFloat(oldValue) - 1;
           // AJAX save would go here
       }
    if(oldValue == 1){
     newVal = parseFloat(oldValue);
     }
     }
     jQueryadd.parent().find("input").val(newVal);
    });
  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <button id="plus" class="btnplus">+</button>
  <div class="qty_pan">
    <input type="text" min="1" max="1000" name="qty" id="qty" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
  </div>
  <button id="minus" class="btnminus">-</button>

now the problem is, when i click on plus button or minus button, the quantity change but it go direct to cart page. i don't know how to cart page link with that. so please help me.

see here on my website

sam
  • 337
  • 5
  • 17

2 Answers2

2

Since default button type is submit, it will submit the form.You need to use event.preventDefault() inside click handling function.

jQuery("#plus, #minus").click(function(e){
   e.preventDefault()
Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
0

Whenever plan to use extra button element except primary submit button in form, best practices says

Always specify the type attribute for <button> element.

Example : Generally use type="button"

<button type="button">Click Me!</button>

So it will not break submit follow.

Kanhaiya lal
  • 101
  • 4