- Posts: 52
- Thank you received: 4
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Scale to set the default answer on var defaultAnsweredScale = 2; // Column of that scale to set as default answer var defaultAnsweredColumn = 3; // Identify this question var thisQuestion = $('#question{self.qid}'); // Identify the scales and columns $('.answer-item[class^="answer_cell_1"]', thisQuestion).addClass('scale-1-item'); $('.answer-item[class^="answer_cell_2"]', thisQuestion).addClass('scale-2-item'); $('tr.answers-list', thisQuestion).each(function(i) { $('.scale-1-item', this).each(function(i) { $(this).addClass('scale-1-column-'+(i+1)+'-item'); }); $('.scale-2-item', this).each(function(i) { $(this).addClass('scale-2-column-'+(i+1)+'-item'); }); }); // Click the default answers $('tr.answers-list', thisQuestion).each(function(i) { if($('.scale-'+defaultAnsweredScale+'-item input[type="radio"]:checked', this).length == 0) { $('.scale-'+defaultAnsweredScale+'-column-'+defaultAnsweredColumn+'-item input[type="radio"]:last', this).click(); } }); }); </script>
LouisGac wrote: For most question types, you have a menu entry called "default answers"
www.limesurvey.org/manual/Question_type_...alues_.28defaults.29
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Set default answers var defaultAnswer = 1; $('select.multiflexiselect', thisQuestion). each(function(i) { if($(this).val() == '') { $(this).val(defaultAnswer); $(this).closest('td.question-item').find('input:hidden:first').attr('value', $(this).val()); } }); }); </script>