How do I stop a form reducing to Zero value?
Posted: Tue Oct 13, 2015 7:47 am
Hi
I am trying to make this + - form prevent it going down to a zero (0).
Cannot quite see how to do that. I'm sure it can be done within its existing Javascript.
Can anyone offer some guidance please.
I am trying to make this + - form prevent it going down to a zero (0).
Cannot quite see how to do that. I'm sure it can be done within its existing Javascript.
Can anyone offer some guidance please.
Code: Select all
<Script>$(window).load(function(){
jQuery(document).ready(function(){
// This button will increment the value
$('.qtyplus').click(function(e){
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = $(this).attr('field');
// Get its current value
var currentVal = parseInt($('input[name='+fieldName+']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$('input[name='+fieldName+']').val(currentVal + 1);
} else {
// Otherwise put a 0 there
$('input[name='+fieldName+']').val(0);
}
});
// This button will decrement the value till 0
$(".qtyminus").click(function(e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = $(this).attr('field');
// Get its current value
var currentVal = parseInt($('input[name='+fieldName+']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
$('input[name='+fieldName+']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
$('input[name='+fieldName+']').val(0);
}
});
});
});//]]>
</script>
<form action='http://www.site.com/cart.asp' method='post' id='myform'>
<input type=hidden name=storeid value=11111>
<input type=hidden name=itemname2 value=trade>
<input type=hidden name=itemcode value='$row->romancode'>";
echo "
<div class='product_carton'>carton quantity</div>
<input type='button' value='-' class='qtyminus' field='quantity' />
<input type='text' name='quantity' value='5' class='qty' />
<input type='button' value='+' class='qtyplus' field='quantity' />