8 Replies Latest reply on Sep 10, 2015 2:16 PM by George_Johnson

# Java script "If the TOTAL price is lower than 65, it should automatically add 15"

I don't know Java script, can someone help me to write this code "If the TOTAL price is lower than 65, it should automatically add 15".

Thanks

• ###### 1. Re: Java script "If the TOTAL price is lower than 65, it should automatically add 15"

Provide the name of the program you are using so a Moderator may move this message to the correct program forum

This Cloud forum is not about help with program problems... a program would be Photoshop or Lighroom or Muse or ???

• ###### 3. Re: Java script "If the TOTAL price is lower than 65, it should automatically add 15"

Do you want this calculation to be in the TOTAL price field or a different one?

• ###### 4. Re: Java script "If the TOTAL price is lower than 65, it should automatically add 15"

Thanks George, It needs to be in a different one.

• ###### 5. Re: Java script "If the TOTAL price is lower than 65, it should automatically add 15"

OK, assuming the name of the TOTAL price field is "TOTAL", the following custom calculation script should work:

// Get the value of the TOTAL field, as a number

var TOTAL = +getField("TOTAL").value;

// Set this field value based on the TOTAL

event.value = TOTAL < 65 ? TOTAL + 15 : TOTAL;

That last line of code is equivalent to the following:

if (TOTAL < 65) {

event.value = TOTAL + 15;

} else {

event.value = TOTAL;

}

• ###### 6. Re: Java script "If the TOTAL price is lower than 65, it should automatically add 15"

Hi George, I thought I would send this image to help explain my project. It's the last 2 cells I can't figure out. As you can see I would choose the item, quantity, price and total for the various lines and that adds up at your order. But it is less 65 it has to add 15 to total.

Thanks

• ###### 7. Re: Java script "If the TOTAL price is lower than 65, it should automatically add 15"

OK, so it looks like you want the shipping fee field to be either 0 or 15, based on the Device Order Price field. If that's correct, the custom calculation script for the shipping fee field could be:

// Get the value of the Device Order Price field, as a number

var price = +getField("DeviceOrderPrice").value;

// Set this field value based on the TOTAL

event.value = price < 65 ? 15 : 0;

but you'd replace "DeviceOrderPrice" with the actual name of the field.

You final Total field would then simply be the sum of the two previous fields. Be sure to set any calculated fields to read-only.

• ###### 8. Re: Java script "If the TOTAL price is lower than 65, it should automatically add 15"

I had to make a correction, so be sure to look at it via the forum rather than email.