• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit

Community Beginner ,
Feb 16, 2024 Feb 16, 2024

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!

TOPICS
How to , JavaScript , PDF forms

Views

303

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Community Expert , Feb 16, 2024 Feb 16, 2024

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

4 Replies 4
Community Expert ,
Feb 16, 2024 Feb 16, 2024

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

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 16, 2024 Feb 16, 2024

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.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Feb 16, 2024 Feb 16, 2024

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

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 17, 2024 Feb 17, 2024

Copied

LATEST

It worked! I cannot thank you enough!