Copy link to clipboard
Copied
Hi all,
I am pretty much at my wit's end here with JavaScript - a programmer I am not. I have 19 groups that consist of 5 questions each. The answers are ranked 1-5 and then totaled. Each group has a corresponding text description - example ( 1 - Ministering - if this is you, you are gifted with the ability to minister to others etc.). I need to find the top 5 ranked responses and then print the item number, the title and the description - example:
1. 25 - Ministering - blah blah blah
2. 24 - Hospitality - blah, blah, blah
3. 21 - Prayer - blah, blah blah
4. 19 - Healing - blah, blah, blah
5. 15 - Giving - blah, blah, blah
So this is what I have for code:
var a=this.getField("Total_g1");
event.value=(a.value*1);
var b=this.getField("Total_g2");
event.value=(b.value*1);
var c=this.getField("Total_g3");
event.value=(c.value*1);
var d=this.getField("Total_g4");
event.value=(d.value*1);
var e=this.getField("Total_g5");
event.value=(e.value*1);
var f=this.getField("Total_g6");
event.value=(f.value*1);
var g=this.getField("Total_g7");
event.value=(g.value*1);
var h=this.getField("Total_g8");
event.value=(h.value*1);
var i=this.getField("Total_g9");
event.value=(i.value*1);
var j=this.getField("Total_g10");
event.value=(j.value*1);
var k=this.getField("Total_g11");
event.value=(k.value*1);
var l=this.getField("Total_g12");
event.value=(l.value*1);
var m=this.getField("Total_g13");
event.value=(m.value*1);
var n=this.getField("Total_g14");
event.value=(n.value*1);
var o=this.getField("Total_g15");
event.value=(o.value*1);
var z=this.getField("Total_g16");
event.value=(p.value*1);
var q=this.getField("Total_g17");
event.value=(q.value*1);
var r=this.getField("Total_g18");
event.value=(r.value*1);
var s=this.getField("Total_g19");
event.value=(s.value*1);
var nums=(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,z,q,r,s);
nums.sort(function(a,b){return b-a});
event.value=(nums[0]); // This number changes in each print line
And well, this doesn't work. Any thoughts? Thanks!!
Deb
Copy link to clipboard
Copied
In want field and action for that field did you place this code?
It looks like you only sorting the response values to each question without keeping track of the question name or grouop.
Do you get any errors saving your code?
With your presented code I get an error about "sort" not being a function, or at least for your variable "nums". It appears you have not declared "nums" as an array. Arrays have a sort method while other types of variables do not.
Are you trying to sort the values of the field objects in the array?
How do you want to handle groups with same total value, ties?
Did you open the Acrobat JavaScript console to see there were any errors in executing your code?
Can you be more specific about how your code does not work?
This will be a large form for a responder to reconstruct, can you provide a link to a sample form?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now