- Posts: 5
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
$(document).ready(function() { // Identify the questions var qID = {QID}; var thisQuestion = $('#question'+qID); var prevMultiChoice = $(thisQuestion).prevAll('.multiple-opt:eq(0)'); // Hide this question $('#question'+qID).hide(); // Find the initial score var totalScore = 0; $('input.checkbox:checked', prevMultiChoice).each(function(i) { var thisScore = $(this).attr('id').slice(-1); totalScore = totalScore + Number(thisScore); }); // Store the score $('input[type="text"]', thisQuestion).val(totalScore); // Listener on the checkboxes $('input.checkbox', prevMultiChoice).change(function(event) { // Find the score totalScore = 0; $('input.checkbox:checked', prevMultiChoice).each(function(i) { var thisScore = $(this).attr('id').slice(-1); totalScore = totalScore + Number(thisScore); }); // Store the score $('input[type="text"]', thisQuestion).val(totalScore); }); });
{score = sum(if(Q1_SQ001 =='Y', 1, 0), if(Q1_SQ002 =='Y', 3, 0), if(Q1_SQ003 =='Y', 1, 0), if(Q1_SQ004 =='Y', 2, 0))}
{if(!is_empty(Q1_SQ001), 1, 0)}
then I show you a really easy way to create these equations.But I wanted something more readable as I have to change the values of this SQ constantly and I have at least 13 SQ in each survey