Code to check quantity for button, but it will not check for enter key
Hello All,
I am a php programmer and not a Javascript programmer and I am trying to help a friend out with his shopping cart. The original programmer (who wrote this years ago and is no longer around) has a button that looks up the quantities in the database for the submitted items, and then displays a prompt if you selected a quantity that is less than the minimum purchase amount.
The issue is if the user enters a smaller amount than allowed and hits the enter key instead of the "Buy" button, it allows the order. I would appreciate any help on how to use the current code to also check for an Enter key submission.I can handle the PHP and the db lookup for minimum quantities.
function checkQuantity(theForm, numQty, minQty) {
if (minQty != -1 && theForm.q.value < minQty) {
alert ("You must buy at least " + minQty + " of this item");
} else if (numQty != -1 && mod(theForm.q.value, numQty) != 0) {
alert ("You must buy in quantities of " + numQty);
} else {
theForm.submit();
}
}
Like I said above. I am hoping to keep the current code and add a hidden field or something like this URL talks about. (sorry for the link to another forum)
Not a solution, but it fixed the issue. If you have a true solution to get both the button and Enter key to do the same thing, I would still like to see it (so I learn how to do it the correct way).
Bookmarks