Administrators Nathan Posted May 14, 2014 Administrators Share Posted May 14, 2014 This is my current code, the quantity11 field has to have an input that is greater than 1 for the form to submit. I have two other fields I need checked as well quantity12 and quantityreg. <script type="text/javascript"> function check() { var elements = document.getElementsByName("quantity11"); for (var i=0; i<elements.length; i++) { var nmbr = parseInt(elements[i].value,10); if (nmbr < 1){ alert("Please add at least 1 treat pack to your order to proceed."); return false; } } return true; } </script> I need to add quantity11, quantity12, and quantityreg all together and then check to see if they are greater than 1 to return true. How can I add them together on the 3rd line? Quote Link to comment Share on other sites More sharing options...
Administrators Nathan Posted May 14, 2014 Author Administrators Share Posted May 14, 2014 <script type="text/javascript"> function check() { var element1 = document.getElementsByName("quantity11"); var element2 = document.getElementsByName("quantity12"); var element3 = document.getElementsByName("quantityreg"); for (var i=0; i<element1.length; i++) { var nmbr1 = parseInt(element1[i].value,10); var nmbr2 = parseInt(element2[i].value,10); var nmbr3 = parseInt(element3[i].value,10); var nmbr = nmbr1 + nmbr2 + nmbr3; if (nmbr < 1){ alert("Please add at least 1 treat pack to your order to proceed."); return false; } } return true; } </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.