3 Replies Latest reply on Sep 1, 2015 8:30 PM by George_Johnson

# Populate one field with one value from choice of four other fields

Hi, I have all but one item on a form working.  Under Calculation of Final Fee there are four different starting points, which self populates depending on what values the user enters in the earlier contract sum and change order fields. How do I populate a fifth field, the Calculated Fee near the bottom of the form, with whichever of the four possible totals shows up under Calculation of Final Fee? My script which isn't working is:

var v1 = this.getField("1Kto50KTotal").value;

var v2 = this.getField("50Kto100Ktotal").value;

var v3 = this.getField("100Kto500Ktotal").value;

var v4 = this.getField("500001andUpTotal").value;

if (v1 !==0) {event.value = v1} else if (v2 !==0) {event.value = v2} else if (v3 !==0) {event.value = v3} else if (v4 !==0) {event.value = v4} else {event.value = ""}

The form looks like:

• ###### 1. Re: Populate one field with one value from choice of four other fields

From what I understand, only one of your 4 first fields can hold a price of some sort and you want that number to be copied to the fifth field.  Why not forget about complex scripting and just add all four fields?  Since the others will be 0, the sum of the 4 fields will be the amount of the only field with a price in it!

Maybe I didn't get what you are trying to achieve?

• ###### 2. Re: Populate one field with one value from choice of four other fields

Thank you, that worked! I'd still like to know what was wrong with the script, must be the way I wrote the last line, just not sure what the correct syntax is.

• ###### 3. Re: Populate one field with one value from choice of four other fields

When you get the value of an empty field, the the result is an empty string. When you compare an empty string using the strict not equal operator (!==) to the number zero, the result is true and you set the result of the calculation to the empty string. If you were to use the != operator, the field value would be coerced to the number 0 if the field is blank. So

"" !== 0 is true

"" != 0 is false