- Posts: 227
- Thank you received: 36
Ask the community, share ideas, and connect with other LimeSurvey users!
<p class="q1-answers" style="display:none;">{if(Q1_a == "Y", ",a", '')}{if(Q1_b == "Y", ",b", '')}{if(Q1_c == "Y", ",c", '')}{if(Q1_d == "Y", ",d", '')}{if(Q1_e == "Y", ",e", '')}{if(Q1_f == "Y", ",f", '')}</p>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); var thisQuestionID = '{QID}'; // Create an array of the Q1 answered codes var q1Answers = $('p.q1-answers', thisQuestion).text().replace(/,/, ''); var q1AnswersArr = q1Answers.split(','); // Shuffle the array function shuffle(o){ for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; } shuffle(q1AnswersArr); // Check the first 3 options in the array $(q1AnswersArr).each(function(i) { if(i < 3) { var thisCode = $.trim(this); $('input[type="checkbox"][id$="X'+thisQuestionID+thisCode+'"]', thisQuestion).prop('checked', true); } }); }); </script>