These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Form to show top 3 results of test results

CreativeGirl
Registered: Oct 31 2010
Posts: 6

I am building a Spiritual Gifts Inventory. When filled out it will show your top 3 Spiritual Gifts.
The form works great with the answers autofilling out the result page that shows the totals for all of the 20 possible traits.
 
Everything works great up until the last 3 form fields.
 
I need these fields to show the Highest, Second highest, third highest result of a 20 different traits.
 
Do I need some Javascript for that function? I don't do Java but am a willing student.
Thanks

Nancy

My Product Information:
Acrobat Pro 9.3.1, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
It's not really clear (to me, at least) what you created so far and what you still want to do.
How does your form work, exactly?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

CreativeGirl
Registered: Oct 31 2010
Posts: 6
You answer 80 questions with a number 0-4. These answers auto fill and total on a results page. That all is pretty simple. What I want to do is take the three highest totals from the results page (there are 20 different totals) and have them auto fill in three separate form fields.

This form is comparable to a personality test, but has 20 different personality types.

I am extremely new to this.

Nancy

CreativeGirl
Registered: Oct 31 2010
Posts: 6
Oh, I want the results to show in text, not the score. I have named each total field with the name of the personality trait.

Nancy

try67
Expert
Registered: Oct 30 2008
Posts: 2398
So you have a list of 20 numeric items and you want to top three?
Then yes, you will need a script for that. What the script should do is collect all of the results into an array, sort the array, and then you can access the first (or last) three items of this array to get the items you need.
Here's how you basically do it:

var arr = new Array(); // define a new array
arr.push(12); // add items to the array, you will need to replace these with the values of your fields, of course
arr.push(1);
arr.push(2);

arr = arr.sort(function(a,b) {return b-a}); // sort the array in descending numerical order

// print out the first three items in the array
console.println(arr[0]);
console.println(arr[1]);
console.println(arr[2]);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

CreativeGirl
Registered: Oct 31 2010
Posts: 6
By saying that I am new to this, I mean that this is the very first form I have build.

This is what I have done with your script:

var arr = new Array(); // define a new array
arr.push(12); // ("Administrtion", "Craftsmanship arts crafts", "Craftsmanship manuel", "Evangelism", "Exhortation", "Faith", "Giving", "Helps", "Hospitality", "Prayer", "Knowledge", "Leadership", "Mercy", "Music vocal", "Music instrumental", "Serving", "Shepherding", "Teaching", "Wisdom");
arr.push(1);
arr.push(2);

arr = arr.sort(function(a,b) {return b-a}); // sort the array in descending numerical order

// print out the first three items in the array
console.println(arr[0]);
console.println(arr[1]);
console.println(arr[2]);

This didn't do anything. It accepted it, but it displays nothing.

I don't want to print I just want it to display. field names are in the area I think you said to place the values of my fields. Did you mean the names of the fields (those are the field names)? I would like it to display the name not a number.

Nancy

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
It is difficult you give you specific direction without seeing the form you're working with. The details are important, and without those, we can give you useful guidance but not useful specifics (e.g., code). If you can post the form somewhere (acrobat.com?), it would help.

What should happen if there are more than three responses equal to 4, or there is one 4 and five 3s? How do you want the top three picked in such cases?
CreativeGirl
Registered: Oct 31 2010
Posts: 6
Oh George, I see your point. Right now I do not have an acrobat.com account. I will look into this and post back.

Thanks for the patients you all have with newbies like me.

Nancy

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You can use JavaScript's sort method of the array object to sort the score in descending order with the associated Spiritual Gift for the score. Form the result of the sort you can get the unique sorted scores and with these values you can obtain the to 3 items including ties. You will have to work out putting the scores and gifts into the array.
  1. // build an array of scores and spiritual gifts;
  2. var aRanking = new Array([10,"Administration"], [11,"Craftsmanship arts crafts"],[25,"Craftsmanship manual"], [24, "Evangelism"], [35,"Exhortation"],[11, "Faith"], [25, "Giving"], [30, "Helps"], [10, "Hospitality"],[15, "Prayer"], [17, "Knowledge"], [18, "Leadership"], [20, "Mercy"],[31, "Music vocal"], [23, "Music instrumental"], [35, "Serving"], [15, "Shepherding"], [14, "Teaching"], [25, "Wisdom"]);
  3.  
  4. // list array before sorting;
  5. console.println("Before:");
  6. for(i = 0; i < aRanking.length; i++) {
  7. console.println(aRanking[i][1] + ": " + aRanking[i][0]);
  8. }
  9. // sort the array of scores and spiritual gifts in descending order;
  10. aRanking = aRanking.sort().reverse();
  11. // list the sorted array;
  12. console.println("\nAfter:");
  13. for(i = 0; i < aRanking.length; i++) {
  14. console.println(aRanking[i][1] + ": " + aRanking[i][0]);
  15. }
  16. // determine the top 3 scores including ties;
  17. // array to hold the top 3 values;
  18. var aTopScore = new Array();
  19. // load first top score
  20. aTopScore[0] = aRanking[0][0];
  21. // get the top most score//loop through scores and gather the unique values;
  22. for(i = 0; i < aRanking.length; i++) {
  23. if(aRanking[i][0] < aTopScore[aTopScore.length - 1]) {
  24. // add to TopScore Array
  25. aTopScore[aTopScore.length] = aRanking[i][0];
  26. } // end if rank score;
  27. } // end loop of array;
  28. // print all unique scores;
  29. console.println('\nUnique scores:\n' + aTopScore.join(', ') );
  30. // print out top 3 scoring gifts;
  31. console.println("\nTop 3 Scores: ");
  32. for(i = 0;i < 3; i++) {
  33. console.println('Score: ' + aTopScore[i]);
  34. // find gifts with this score;
  35. for(j = 0; j < aRanking.length; j++) {
  36. if(aRanking[j][0] == aTopScore[i]) {
  37. console.println(" Spiritual Gift: " + aRanking[j][1]);
  38. }
  39. if(aRanking[j][0] < aTopScore[i]) {
  40. break;
  41. }
  42. } // end loop for gifts;
  43. } // end loop for scores;

Results for above code:

Quote:
Before:
Administration: 10
Craftsmanship arts crafts: 11
Craftsmanship manual: 25
Evangelism: 24
Exhortation: 35
Faith: 11
Giving: 25
Helps: 30
Hospitality: 10
Prayer: 15
Knowledge: 17
Leadership: 18
Mercy: 20
Music vocal: 31
Music instrumental: 23
Serving: 35
Shepherding: 15
Teaching: 14
Wisdom: 25

After:
Serving: 35
Exhortation: 35
Music vocal: 31
Helps: 30
Wisdom: 25
Giving: 25
Craftsmanship manual: 25
Evangelism: 24
Music instrumental: 23
Mercy: 20
Leadership: 18
Knowledge: 17
Shepherding: 15
Prayer: 15
Teaching: 14
Faith: 11
Craftsmanship arts crafts: 11
Hospitality: 10
Administration: 10

Unique scores:
35, 31, 30, 25, 24, 23, 20, 18, 17, 15, 14, 11, 10

Top 3 Scores:
Score: 35
Spiritual Gift: Serving
Spiritual Gift: Exhortation
Score: 31
Spiritual Gift: Music vocal
Score: 30
Spiritual Gift: Helps

true

George Kaiser

CreativeGirl
Registered: Oct 31 2010
Posts: 6
In line 2 I see is where you have the array of scores & gifts. The scores are determined by the person filling out the form. Would I just take out the scores and leave the gifts?Do I copy and past only the black and have to change the green and red details to match my form?

I have really taken a big bite for a project.
Thank you for teaching me.

Nancy