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

Calculating averages but excluding some radio buttons.

Community Beginner ,
Jul 11, 2018 Jul 11, 2018

I am building a simple call monitoring form. I want the user to be able to select a radio button for each phase of the call, for example:

Call Opening  [radio button 1] [radio button 2] [radio button 3] [radio button 4] [N/A]

Objection handling [radio button 1] [radio button 2] [radio button 3] [radio button 4] [N/A]

Effective Questioning  [radio button 1] [radio button 2] [radio button 3] [radio button 4] [N/A]

Postioning  [radio button 1] [radio button 2] [radio button 3] [radio button 4] [N/A]

Call Closing[radio button 1] [radio button 2] [radio button 3] [radio button 4] [N/A]

Where radio button 1 = 1, 2 = 2, 3 = 3, 4 = 4.

Using the built-in functions I created a field that displays the averages of the radio button groups. I've been asked to include an N/A option for each of the sections so that if the user selects radio button 4 for filed one, radio button 3 for field 2 and N/A for the remaining fields the sore won't pick up the calculation for the N/A selections.

Is there a way to exclude any field that has N/A from the calculation using Simplified field notation or some other option?

Please note, I have no experience using SFN or java script.

TOPICS
PDF forms
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jul 12, 2018 Jul 12, 2018

You can use this code to achieve it:

var fields = ["CallPrepRB", "EffQRB", "ActLisRB", "CallPosRB", "CallCloseRB"];

var total = 0;

var n = 0;

for (var i in fields) {

    var f = this.getField(fields);

    if (f.valueAsString=="Off") continue;

    var v = Number(f.valueAsString.replace("Choice", ""));

    total+=v;

    n++;

}

if (n==0) event.value = "";

else event.value = total/n;

View solution in original post

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

Yes, this can be done using a script. What are the names of the fields involved?

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

Hi, the fields are:

Fields:

SCORE - Properties = Text Box

Radio button filed name and choice names. please note, choice five is the N/A option.

Field Name: CallPrepRB

  • Choice1
  • Choice2
  • Choice3
  • Choice4
  • Choice5

Field Name: EffQRB

  • Choice1
  • Choice2
  • Choice3
  • Choice4
  • Choice5

Field Name: ActLisRB

  • Choice1
  • Choice2
  • Choice3
  • Choice4
  • Choice5

Field Name: CallPosRB

  • Choice1
  • Choice2
  • Choice3
  • Choice4
  • Choice5

Field Name: CallCloseRB

  • Choice1
  • Choice2
  • Choice3
  • Choice4
  • Choice5

Below is an image of the page:

pdfformcapture.PNG

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

You can use this code to achieve it:

var fields = ["CallPrepRB", "EffQRB", "ActLisRB", "CallPosRB", "CallCloseRB"];

var total = 0;

var n = 0;

for (var i in fields) {

    var f = this.getField(fields);

    if (f.valueAsString=="Off") continue;

    var v = Number(f.valueAsString.replace("Choice", ""));

    total+=v;

    n++;

}

if (n==0) event.value = "";

else event.value = total/n;

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

Try67 thank you for spending some time on this and creating the code.  I've entered the code you created into the form, however, the N/A button when selected is calculating in the average. Screenshot included. Am I doing something wrong?

pdfformcapture2.PNG

pdfformcapture2.1.PNG

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

No, it's my mistake... Change this line:

if (f.valueAsString=="Off") continue;

To:

if (f.valueAsString=="Off" || f.valueAsString=="Choice5") continue;

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

try67, It worked! Thank you so much. Sending you virtual high fives and seriously good karma.  You are a rock star.

For anyone else looking to do something similar this is the code:

var fields = ["CallPrepRB", "EffQRB", "ActLisRB", "CallPosRB", "CallCloseRB"]; 

var total = 0; 

var n = 0; 

for (var i in fields) { 

    var f = this.getField(fields); 

    if (f.valueAsString=="Off" || f.valueAsString=="Choice5") continue; 

    var v = Number(f.valueAsString.replace("Choice", "")); 

    total+=v; 

    n++; 

if (n==0) event.value = ""; 

else event.value = total/n; 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 31, 2022 Mar 31, 2022

i am trying to do something almost identical to the last user but can't make it work. help!

 

here are my fields: "JK", "WQ", "AP", "I", "CLS", "D",  and "O"

here are the options for the radio button fields: ChoiceNA, Choice1, Choice2, Choice3

here is the code that I entered:

 

var fields = ["JK", "WQ", "AP", "I", "CLS", "D", "O"];

var total = 0;

var n = 0;

for (var i in fields) {

var f = this.getField(fields);

if (f.valueAsString=="Off" || f.valueAsString=="ChoiceNA") continue;

var v = Number(f.valueAsString.replace("Choice", ""));

total+=v;

n++;

}

if (n==0) event.value = "";

else event.value = total/n;

 

 

ncluce_0-1648752964848.png

 

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

Change this line:

var f = this.getField(fields);

To:

var f = this.getField(fields[i]);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 31, 2022 Mar 31, 2022
LATEST

It worked. You are a wizard. Thank you.

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

The "Simplified Field Notation" does not support any conditional JavaScript statements. The "Field is the Average of the following fields" will include the "N/A" choices as a zero value and count in the computation of the average. That leaves only the "Custom calculation script". One can create a variable array and then use JavaScript to place each field's value into an element in the array. Then one can use the "filter" method of the array object to remove the "N/A" items from the array. Now one can compute the average using the array of values with the "N/A" items removed. It is the sum of the elements divided by the number of elements in the array. If there are no elements in the array the average cannot be computed.

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

Gkaiseril, thank you for your response. To be honest, I think this is beyond my current skill level. Do you know of any web resource that demonstrates this?

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