Copy link to clipboard
Copied
I am creating an assessment with 10 questions where a person will have to choose a score between 0 and 4 for each question. This is a standard Likert scale of 0=never, 1=almost never, 2=sometimes, 3=faily often, 4=very often.
The assessment, however, has some questions that are "positive" questions and some that are "negative" questions. For example, "how often have you felt nervous and stressed" is a negative question while "how often have you felt confident" is a positve question.
Then, when I tally the results within the form, I want to reverse their scores for every positve question such that:
- if they entered 0, what gets calculated in the total is a 4
- if they entered 1, what gets calculated in the total is a 3
- if they entered 2, what gets calculated in the total is still a 2
- if they entered 3, what gets calculated in the total is a 1
- if they entered 4, what gets calculated in the total is a 0
I don't know how to write java script so I'm hoping someone can just give me the actual string of text so I can copy it and paste it into my Adobe form creator.
And I assume this will go into the Custom Calculation Script of the calculate tab in the Text Field Properties.
Thaksn for any help.
Copy link to clipboard
Copied
Actually, you can't set dropdown the way I was thinking.
Just leave everything as it is and replace this line:
var pos = f1+f2+f3+f4+f5+f6+f7+f8;
event.value = total+pos;
with this:
var pos = f1+f2+f3+f4+total;
event.value = pos;
Copy link to clipboard
Copied
var fields = ["Careless","Disorganized","Inefficient", "Sloppy"];
var total = 0;
for(var i in fields){
var f = this.getField(fields[i]).valueAsString;
if(f==="1")total+=9;
if(f==="2")total+=8;
if(f==="3")total+=7;
if(f==="4")total+=6;
if(f==="5")total+=5;
if(f==="6")total+=4;
if(f==="7")total+=3;
if(f==="8")total+=2;
if(f==="9")total+=1;
}
var f1= Number(this.getField("Careless").valueAsString);
var f2= Number(this.getField("Disorganized").valueAsString);
var f3= Number(this.getField("Efficient").valueAsString);
var f4= Number(this.getField("Inefficient").valueAsString);
var f5= Number(this.getField("Organized").valueAsString);
var f6= Number(this.getField("Practical").valueAsString);
var f7= Number(this.getField("Sloppy").valueAsString);
var f8= Number(this.getField("Systematic").valueAsString);
var pos = f1+f2+f3+f4+total;
event.value = pos;
This results in a 32, when we're still looking for 8. +total would count the f1-f4 fields twice wouldn't it?
Copy link to clipboard
Copied
I noticed the reverse scored fields weren't correctly associated and fixed it, and now it's resulting in a 40.
var fields = ["Careless","Disorganized","Inefficient", "Sloppy"];
var total = 0;
for(var i in fields){
var f = this.getField(fields[i]).valueAsString;
if(f==="1")total+=9;
if(f==="2")total+=8;
if(f==="3")total+=7;
if(f==="4")total+=6;
if(f==="5")total+=5;
if(f==="6")total+=4;
if(f==="7")total+=3;
if(f==="8")total+=2;
if(f==="9")total+=1;
}
var f1= Number(this.getField("Careless").valueAsString);
var f2= Number(this.getField("Disorganized").valueAsString);
var f3= Number(this.getField("Efficient").valueAsString);
var f4= Number(this.getField("Inefficient").valueAsString);
var f5= Number(this.getField("Organized").valueAsString);
var f6= Number(this.getField("Practical").valueAsString);
var f7= Number(this.getField("Sloppy").valueAsString);
var f8= Number(this.getField("Systematic").valueAsString);
var pos = f1+f2+f4+f7+total;
event.value = pos;
Copy link to clipboard
Copied
You have changed fields in variables, here try this script:
var fields = ["Careless","Disorganized","Inefficient","Sloppy"];
var total = 0;
for(var i in fields){
var f = this.getField(fields[i]).valueAsString;
if(f==="1")total+=9;
if(f==="2")total+=8;
if(f==="3")total+=7;
if(f==="4")total+=6;
if(f==="5")total+=5;
if(f==="6")total+=4;
if(f==="7")total+=3;
if(f==="8")total+=2;
if(f==="9")total+=1;
}
var f1= Number(this.getField("Efficient").valueAsString);
var f2= Number(this.getField("Organized").valueAsString);
var f3= Number(this.getField("Practical").valueAsString);
var f4= Number(this.getField("Systematic").valueAsString);
var pos = f1+f2+f3+f4+total;
event.value = pos;
Copy link to clipboard
Copied
That worked, thank you!
Copy link to clipboard
Copied
You didn't change field names in the script to your actual field names.
Try now:
var fields = ["4","5","7","8"];
var total = 0;
for(var i in fields){
var f = this.getField(fields[i]).valueAsString;
if(f==="0")total+=4;
if(f==="1")total+=3;
if(f==="2")total+=2;
if(f==="3")total+=1;}
var f1= Number(this.getField("1").valueAsString);
var f2= Number(this.getField("2").valueAsString);
var f3= Number(this.getField("3").valueAsString);
var f4= Number(this.getField("6").valueAsString);
var f5= Number(this.getField("9").valueAsString);
var f6= Number(this.getField("10").valueAsString);
var pos = f1+f2+f3+f4+f5+f6;
event.value = total+pos;
Copy link to clipboard
Copied
YES! That was it. My field names were not changed correctly. THANK YOU!
Such a huge help Nesa (and great catch on that Try67).
Much appreciated.
Have a great weekend.
You rock!