- Posts: 12
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the group scores var scores = { G1: 370, G2: 100, G3: 210, G4: 75, G5: 300 }; // 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('<br />'+key+': '+value+''); // Insert into textarea $('textarea', thisQuestion).val($('textarea', thisQuestion).val()+key+': '+value+'\n'); } }); </script>
{sum(G1Q1.value, G1Q2.value, G1Q3.value,...)}
{sum(G2Q1.value, G2Q2.value, G2Q3.value,...)}
<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('<br />'+key+': '+value+''); // Insert into textarea $('textarea', thisQuestion).val($('textarea', thisQuestion).val()+key+': '+value+'\n'); } }); </script>
No, the JavaScript will work with arrays. Load the equation questions with the assessments for the array sub-questions.Thanks a million for this. My current question type is array and I see that this will have to change to list (radio) for the javascript to work.
{sum(Q1_SQ001.value, Q1_SQ002.value, Q1_SQ003.value,...)}