1 Reply Latest reply on Jan 31, 2017 11:33 AM by gkaiseril

    Sorting 19 calculations to list the top 5 and then add a description based on results

    Debbie HP

      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");


      var b=this.getField("Total_g2");


      var c=this.getField("Total_g3");


      var d=this.getField("Total_g4");


      var e=this.getField("Total_g5");


      var f=this.getField("Total_g6");


      var g=this.getField("Total_g7");


      var h=this.getField("Total_g8");


      var i=this.getField("Total_g9");


      var j=this.getField("Total_g10");


      var k=this.getField("Total_g11");


      var l=this.getField("Total_g12");


      var m=this.getField("Total_g13");


      var n=this.getField("Total_g14");


      var o=this.getField("Total_g15");


      var z=this.getField("Total_g16");


      var q=this.getField("Total_g17");


      var r=this.getField("Total_g18");


      var s=this.getField("Total_g19");


      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!!


        • 1. Re: Sorting 19 calculations to list the top 5 and then add a description based on results
          gkaiseril MVP & Adobe Community Professional

          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?