Copy link to clipboard
Copied
I have a photography order form (attached) where if the following sized items are ordered, then shipping and handling is $15.99: 10x20, 8x16, 10x30, 8x24 and 5x15 (each field's total is named is named Total - e.g., 10x20Total). All other sizes shipping and handling would be $7.99. So I'm assuming the code would be if any of the first sets of sizes is greater than 0, then S&H is $15.99; otherwise smaller sizes S&H is $7.99.
Just so you know, after reading through other posts, I did enter if(this.getField("10x20Total").value > 0)event.value=15.99 as a test, but when I deleted the order for a 10x20, the $15.99 remained.
I've attached a copy of the order form, and greatly appreciate any assistance with this!
Copy link to clipboard
Copied
Use this:
var f1 = ["10x20", "8x16", "10x30", "8x24", "5x15"];
var f2 = ["11x14", "8x10", "5x7", "4x6", "Wallets", "5x10", "Magnet", "LuggageTags", "Keychain"];
var shipping = 0;
function checkFields(fields, cost) {
for (var i=0; i<fields.length; i++) {
if (this.getField(fields[i]).valueAsString !== "") {
return cost;}}
return 0;}
shipping = checkFields(f1, 15.99) || checkFields(f2, 7.99);
event.value = shipping;
Copy link to clipboard
Copied
You need to use 'else' to set field to empty:
if(this.getField("10x20Total").value !== "")
event.value = 15.99;
else
event.value = "";
You will need to add another condition to check for second shipping 7.99
Copy link to clipboard
Copied
Thank you so much for providing this answer! What would I use if I need multiple values be part of the $15.99 shipping (e.g., 10x20, 8x16, 10x30, 8x24 and 5x15)? Again, I'm not a coder so I just don't know these things.
Copy link to clipboard
Copied
Use this:
var f1 = ["10x20", "8x16", "10x30", "8x24", "5x15"];
var f2 = ["11x14", "8x10", "5x7", "4x6", "Wallets", "5x10", "Magnet", "LuggageTags", "Keychain"];
var shipping = 0;
function checkFields(fields, cost) {
for (var i=0; i<fields.length; i++) {
if (this.getField(fields[i]).valueAsString !== "") {
return cost;}}
return 0;}
shipping = checkFields(f1, 15.99) || checkFields(f2, 7.99);
event.value = shipping;
Copy link to clipboard
Copied
It worked! I cannot thank you enough!