- Posts: 1128
- Thank you received: 329
Ask the community, share ideas, and connect with other LimeSurvey users!
$(document).ready(function() { var ACT = '{ASSESSMENT_CURRENT_TOTAL}'; var SGQ = '10002X65X1215'; // LS < 1.91 // var SGQ = '{SGQ}'; // LS > 1.92 if(ACT == 0) document.getElementById('answer'+SGQ+'A0').checked=true; if(ACT == 2) document.getElementById('answer'+SGQ+'A1').checked=true; if(ACT >= 3) document.getElementById('answer'+SGQ+'A2').checked=true; // document.limesurvey.submit(); });
<script type="text/javascript" charset="utf-8"> $(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); }); }); </script>