Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How do I rank group assessment output?

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 5 months ago #144763 by tpartner
Replied by tpartner on topic How do I rank group assessment output?
I think this should do what you want - return only the group names in one line.

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Define the group scores
    var scores = {
      G1: {equation1},
      G2: {equation2},
      G3: {equation3},
      G4: {equation4},
      G5: {equation5}
    };
 
    // Sort the array
    var tuples = [];    
    for (var key in scores) tuples.push([key, scores[key]]);    
    tuples.sort(function(a, b) {
      a = a[1];
      b = b[1];
 
      return a < b ? -1 : (a > b ? 1 : 0);
    });  
 
    // Loop through the sorted array  
    for (var i = 0; i < tuples.length; i++) {
      var key = tuples[i][0];
      var value = tuples[i][1];
 
      // Display in question text
      $('.question-text', thisQuestion).append(key+' ');
 
      // Insert into textarea
      $('textarea', thisQuestion).val($('textarea', thisQuestion).val()+key+' ');
    }
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: InfoSolutionsProvider
The topic has been locked.
  • InfoSolutionsProvider
  • InfoSolutionsProvider's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 5 months ago #144778 by InfoSolutionsProvider
Replied by InfoSolutionsProvider on topic How do I rank group assessment output?
Hi Tony,

Great stuff! Works perfectly, thanks so much!!

I know people call you the JS guru on this platform, but I think you're much more than that. ;)

Really great to have your help on this project.

Fatai
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose