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.
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;
Copy link to clipboard
Copied
Yes, this can be done using a script. What are the names of the fields involved?
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
Field Name: EffQRB
Field Name: ActLisRB
Field Name: CallPosRB
Field Name: CallCloseRB
Below is an image of the page:
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;
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?
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;
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;
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;
Copy link to clipboard
Copied
Change this line:
var f = this.getField(fields);
To:
var f = this.getField(fields[i]);
Copy link to clipboard
Copied
It worked. You are a wizard. Thank you.
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.
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?