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

Calculating averages but excluding some radio buttons.

Community Beginner ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

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

Views

1.2K

Translate

Translate

Report

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

correct answers 1 Correct answer

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;

Votes

Translate

Translate
Community Expert ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

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

To:

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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; 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Change this line:

var f = this.getField(fields);

To:

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

It worked. You are a wizard. Thank you.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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