• Need to create conditional calculation script that...

# Need to create conditional calculation script that will add the results if greater than or equal 3

New Here ,
Jul 30, 2022 Jul 30, 2022

Copied

I am creating a form where someone will respond to 75 statements (with each being a different field) on a likert scale of 0 to 4.  I can figure out how to create a calculation of the sum of all the fields but I also need to create a conditional calculation script that will look at the value for each statement and if the value is greater than or equal to 3 it adds the value into the total.  If it is 2 or less, then it can be left out of the calculation.

so it might look like:

Question1 = 3

Question2 = 2

Question3 = 4

Question4 = 1

Question5 = 3

Question6 = 3

Question7 = 2

Question8 = 4

Question9 = 3

Question10 = 2

So ideally, the script would be able to recognize that Question2, Question3, Question5, Question6, Question8, and Question9 would be added together into a total.  so 3+4+3+3+4+3 = 20

Any help would be greatly appreciated

thanks

TOPICS
How to , JavaScript

Views

41

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
4 Replies 4
Jul 31, 2022 Jul 31, 2022

Copied

If 'Question1-10' are field names you can do it like this:

var total = 0;
for( var i=1; i<=10; i++){
if(this.getField("Question"+i).valueAsString != "" && Number(this.getField("Question"+i).value) >= 3)
total += Number(this.getField("Question"+i).value);}
event.value = total;

If you have 75 'Question' fields replace 10 with 75.

Likes

Report

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

Copied

This is so great thank you!   One additional favor.  Same scenario but instead of adding all of them together, I just want to create a count of how many of the 75 questions have scores equal to or greater than 3.

thank you again,

Likes

Report

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

Copied

LATEST

Just change this line:

total += Number(this.getField("Question"+i).value);

to:

total++;

Likes

Report

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

Copied

This is great thank you. Another favor please. Same scenario but instead
of adding the values of any responses equal to or greater than 3, I'd like
to simply count the number of responses that are equal to or greater than 3

Richard

--
Richard Tyler-Walker, PhD/LCMHC-S

Associate Director of Operations
Past President, American College Counseling Association

*Pronouns: he/him/his*

Counseling Center
NC State University

2815 Cates Ave. Box 7312

Raleigh, NC 27695-7312

919-515-2423

retyler@ncsu.edu

fax: 919-515-8525

-Confidentiality Notice -
This electronic mail transmission may include information that is
confidential and exempt from disclosure under federal and/ocr state laws,
including without limitations, the Health Insurance Portability and
Accountability Act of 1996 and Family Educational Rights and Privacy Act.
It is the policy of the Counseling Center that the sender did not intend
this transmission to be sent to or received by any unauthorized persons and
is not waiving the confidentiality or privileged nature of such information.

If you are not the intended recipient of this electronic mail transmission
immediately delete it from your computer system without copying it. In
919-515-2423. This way, we can correct our address for the intended
recipient.

[image: Link to ACCA Website] <>

Likes

Report

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