if/then summation not working properly
In an order form, I would like a field to stay blank unless a quantity has been purchased, so I am writing code instead of using the basic option of selecting fields (which works). I need a total number of t-shirts purchased based on five sizes. At first, it seems to work, but with no reason I can detect, it stops adding the numbers and instead treats them like a string. Example: 5xs + 5m gives me 10total. Then if I add another 5l, I get 555 as the sum. (The shirt sizes and quantities are irrelevant to the outcome.) Obviously, there are more advanced ways of doing this that go way above my level of knowledge, but can anyone tell me where the problem is?
var qty1 = this.getField("qTYikmpxs").value;
var qty2 = this.getField("qTYikmps").value;
var qty3 = this.getField("qTYikmpm").value;
var qty4 = this.getField("qTYikmpl").value;
var qty5 = this.getField("qTYikmpxl").value;
if( (qty1 + qty2 + qty3 + qty4 + qty5) > 0) event.value = qty1 + qty2 + qty3 + qty4 + qty5;
else event.value = "";
The second recurring problem is that the first purchase field on the form stays blank in the total field until a second quantity ANYWHERE else on the form is selected. It doesn't matter if it is the product immediately below or on another page; only when something else is selected does the product show up.
Quantity can be any number; Price is set as blank until a quantity above zero is entered; TOTAL is the product of both fields. Same formula in every similar TOTAL cell (modified for product name, of course), and it works everywhere immediately, and on first line when more data is entered. I have a 'clear form' button at the top of the page, but see no reason for it to complicate things.
Thanks for any help.
