How do I use an IF OR function in Javascript to check if a textbox value is not empty and greater than 0?
Check out the code snippet below:
if(qty !== "" && qty !== "0"){
//
}
Here, qty refers to the name and id of the HTML input field.
This excerpt is part of an updated JavaScript code that includes additional functionality for verifying quantity inputs before adding items to the basket:
if(qty !== "")
{
if(/^\d+$/.test(qty.value)){
var value = parseInt(qty.value, 10);
sizeID = document.getElementById("size" + colID + prodID).value;
window.location = "/_nCartAddToBasket.asp?ProductID=" + prodID + "&ProductColourID=" + colID + "&ProductSizeID=" + sizeID + "&Qty=" + qty + "&fgID=" + fgID;
} else {
alert("You must enter a numeric value in the quantity field.");
}
} else {
alert("You must enter a quantity before adding to your basket.");
}
}