Jump to content

Recommended Posts

  • Administrators
Posted

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?

  • Administrators
Posted

<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>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...