I am using Javascript to validate the quantity added to a shopping cart written in PHP. The cart sells pipes which come in different pack amounts and different lengths.
The quantity is added to the cart as a zero, the user then changes the quantity and this is validated to make sure it is a pack quantity or is divisible by the UOM (Unit of measure of pipe).
Everything works like clockwork when the user adds an item to the cart, changes it quantity to the required amount, adds another item, changes its quantity, etc.
The problem is when the user adds a couple of items to the cart without changing quantities, and then attempts to change the quantities. The validation gives an error message to the other items zero values even if the item line is being changed is a buyable quantity.
I need a way of ignoring any zero values (which it isn't).
The quantity is added to the cart as a zero, the user then changes the quantity and this is validated to make sure it is a pack quantity or is divisible by the UOM (Unit of measure of pipe).
Everything works like clockwork when the user adds an item to the cart, changes it quantity to the required amount, adds another item, changes its quantity, etc.
The problem is when the user adds a couple of items to the cart without changing quantities, and then attempts to change the quantities. The validation gives an error message to the other items zero values even if the item line is being changed is a buyable quantity.
I need a way of ignoring any zero values (which it isn't).
Code:
echo"<td><INPUT TYPE=text class=\"box\" size=3 name=quantity[$product_id] value=\"$quantity\" onChange=\"validate(this.value)\"></td>";
?>
<script language="javascript1.2" src="validations.js"></script>
<script language="javascript1.2">
<!--
function validate(thisform){
x = "<?=$uom_conv?>" // UOM (Unit of Measure)
y = thisform // ORDER QUANTITY
z = "<?=$pack_qty?>" // PACK QUANTITY
if (y == 0) {
return;
}
with (Math) {
temp1 = max((x),(y));
temp2 = min((x),(y));
val1 = temp1/temp2;
}
val1 += ''
if(!isInteger(val1)){
alert("*ORDER ALERT*\rOrder Quantity is not a Multiple of Stick/Coil Length\nPlease re-enter order quantity");
window.location.reload()
return false;
}
with (Math){
temp3 = max((y),(z));
temp4 = min((y),(z));
val2 = temp3/temp4;
}
val2 += ''
if(!isInteger(val2)){
ConfirmStatus = confirm("*WARNING*\rNot a complete pack quantity, do\nyou wish to continue with this order?");
if (ConfirmStatus == true) {
return true;
}else{
window.location.reload()
return false;
}
}
}
//-->
</script>