
1. Re: Sum two fields then Divide by 2
gkaiseril Jul 7, 2016 4:03 AM (in response to Monteigo99)You could put your calculation into the "Simplified Field Notation" method option.
If I remember correctly adding a number to itself and dividing by 2 will result in the number.
Have you looks at any of the free tutorials or videos on form creation?

2. Re: Sum two fields then Divide by 2
try67 Jul 7, 2016 4:07 AM (in response to gkaiseril)If the field names contain spaces, though, you'll need to escape them, like this:
JJPC\ MCKTOTAL1

3. Re: Sum two fields then Divide by 2
Monteigo99 Jul 7, 2016 12:21 PM (in response to gkaiseril)Thank you. The two fields are different; they have different names. I can't use the simplified field because it doesn't have secondary functions; e.g. it will add ONLY, but will not then divide.
I'm an advanced form creator, except when it comes to JavaScript.
I've searched all over the internet for this script, but all I get is simple tutorials that do not provide the structure of the entire syntax with all the {,},; etc. I don't know how to structure the script properly.

4. Re: Sum two fields then Divide by 2
try67 Jul 7, 2016 12:32 PM (in response to Monteigo99)1 person found this helpfulThe basic structure of the script would be:
var v1 = Number(this.getField("FieldName1").valueAsString); var v2 = Number(this.getField("FieldName2").valueAsString); event.value = (v1+v2)/2;

5. Re: Sum two fields then Divide by 2
gkaiseril Jul 7, 2016 1:03 PM (in response to Monteigo99)Not true. If you divide by a constant nonzero value it should work.

6. Re: Sum two fields then Divide by 2
Monteigo99 Jul 7, 2016 1:07 PM (in response to try67)It worked! Thank you.
var v1 = Number(this.getField("JJPC_MCKTOTAL1").valueAsString);
var v2 = Number(this.getField("JDPC_MCKTOTAL1").valueAsString);
event.value = (v1+v2)/2;

7. Re: Sum two fields then Divide by 2
Monteigo99 Jul 13, 2016 4:59 PM (in response to try67)So, the above script works but I just figured out that I need the event.value to only calculate if v2 is >0. I tried this but it didn't work. Any assistance is appreciated.
var v1 =
Number(this.getField("JJPC_MCKTOTAL1").valueAsString);var v2 =
Number(this.getField("JDPC_MCKTOTAL1").valueAsString);event.value = If((v2>0),(v1+v2)/2,v1);

8. Re: Sum two fields then Divide by 2
try67 Jul 14, 2016 3:30 AM (in response to Monteigo99)What should be the value of the field if that condition is not true?

9. Re: Sum two fields then Divide by 2
Monteigo99 Jul 14, 2016 8:18 AM (in response to try67)If V2>0, then add v1+v2, if it is false, then v1.
Is that what you're asking?
Thanks

10. Re: Sum two fields then Divide by 2
Monteigo99 Jul 14, 2016 10:13 AM (in response to try67)I've derived this formula that works for 5 of 6 fields. On the 6th field it is a one adjustment calculation delayed (I have 5 Y/N drop down list options that get calculated in a field, one for the first 6mths, then on another field for the second 6 mths).
What's wrong with this?
var v1 =
Number(this.getField("JJNotesCompletionRate").valueAsString);var v2 =
Number(this.getField("JDNotesCompletionRate").valueAsString);if(v2>0) {
event.value = (v1+v2)/2;
} else {
event.value = v1;}

11. Re: Sum two fields then Divide by 2
try67 Jul 14, 2016 11:20 AM (in response to Monteigo99)1 person found this helpfulThr code is fine. The issue is with the Fields Calculation Order.

12. Re: Sum two fields then Divide by 2
Monteigo99 Jul 14, 2016 11:58 AM (in response to try67)Yep, that's what I found. It works now. Thank you