5 Replies Latest reply on Dec 3, 2012 8:02 AM by woodoochildx

Need Help by some % calculation

Hi Guys,

i need some help calculating something.

I have 5 boxes; "boxA" - "boxB" - "boxC" - "boxD" and "boxE". Box A–C are sums coming from other fields.

"boxD" represent the VTA – and can be just 19% ore 0%.

This means that "boxE" = ("boxA" + "boxB" + "boxC") * "boxD" ("box D" is equal with 0,19  – if the customer types 19% in the field – ore "0" (zero) – by leaving the "boxD" empty or typing the value "0" inside. A multiplication with 0 would be false, so it had to be ignored if the content of the "boxD" is 0)

I suppose it will be something with "if" and "else" but how i say, I'm a greenhorn in this domain.

Actually i found something that could help but i thing some parts – the definition of var v4, if v4 get the value 19% ore 0% – are missing.

(function() {

// Get the field values, as numbers

var v1 = +getField("boxA").value;

var v2 = +getField("boxB").value;

var v3 = +getField("boxC").value;

var v4 = +getField("boxD").value;

// I suppose here comes some "if" "else" stuff for the definitoon of var4

// Perform the calculation; the result is the content of the "boxE"

var result = v4 * (v1 + v2 + v3);

// Set the value of this field to the result

event.value = result;

})();

• 1. Re: Need Help by some % calculation

So basically you want to check if boxD is not empty (or zero), and if that's the case use it in the calculation, right?

So you can use something like this:

var result = (v1 + v2 + v3);

if (v4!=0) {

result *= (v4/100)

}

(this will also cover the instances where boxD is empty, since that would be converted to zero by the "+" operator you used.

• 2. Re: Need Help by some % calculation

I try to make my problem more understandable, so i make some image :-)

• 3. Re: Need Help by some % calculation

Yes, I understood it. The code I provided does just that.

• 4. Re: Need Help by some % calculation

I would make sure you are not having a problem with using the "," as the decimal separator.

What problem are you having?

Is there an error in the JavaScript console?

If so, what is the exact wording?

Have you examined the values within the script to make sure you are getting the value you are expecting?

• 5. Re: Need Help by some % calculation

hi guys

thanks for the help! …actually i do some other work but i'm gonna come back to your sollution and try it. :-)

my feedback comes soon…