Zoom button not working in magento
I am using magento 1.8.1. I am using magento 1.8.1 and I have changed the increment decrement scripts. with a design change.
jQuery(function() {
jQuery("div.add-to-cart .qty_pan").append('<div class="inc add">›</div><div class="dec add">‹</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 that when i click the plus or minus button the quantity changes, but it goes straight to the cart page. I don't know how to link to this page. so please help me.
see here on my website
Since the default button type is submit, it will submit the form. You need to use the function event.preventDefault()
inside the click handling function.
jQuery("#plus, #minus").click(function(e){
e.preventDefault()
When planning to use an additional button element other than the main submit button on a form, best practices say
Always specify the type attribute on an element
<button>
.
Example: usually use type="button"
<button type="button">Click Me!</button>
So it won't break.