Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Issues with the Default values in array questions Workaround

  • NielsFro
  • NielsFro's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 1 month ago #159189 by NielsFro
Hi all,

I am creating a survey in which I predominantly use array questions. As all questions are mandatory, I want to facilitate completing the survey by always checking the last answer option (answer range from 0%, 10%, ... 100%, no answer; no answer is not set by the survey standards, but is an own answer option - hope you know what I mean?)

I have used a dual-array scale previously, in which the assignment of a default answer worked perfectly using the respective workaround. However now, using only a normal array, it does not work anymore, nothing is checked...
I followed these instructions www.limesurvey.org/manual/Workarounds:_M...s_in_array_questions and also tested if javascript is active by the "Alert", which works fine. My LS version is 2.51.0+160829

This is the code that I put into the "Source" of the question (as you can see, my question ID is 1016, at least I suppose that it is as the title says Edit question: WssbgrdeUndNgr (ID:1016) )

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// A function to pre-check a column of an array
function checkedDefault(qID, column) {
var checkedCol = column - 1;
$('#question'+qID+' tr.subquestions-list').each(function(i) {
if ($('input.checkbox:checked', this).length == 0) {
$('input.checkbox:eq('+checkedCol+')', this).prop('checked', true);
$('input.checkbox:eq('+checkedCol+')', this).parent().find('input[type="hidden"]').val(1);
}
});
}
// Call the function with a question ID and column number
checkedDefault(1016, 12);
});

</script>

Looking forward to your replies! Thanks a lot
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 1 month ago #159210 by tpartner
This script will render the last column of an array as "default" answer.

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Default answers
    $('tr.answers-list', thisQuestion).each(function(i) {
      if($('input[type="radio"]:checked', this).length == 0) {
        $('input[type="radio"]:last', this).trigger('click')
      }
    });
  });
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: NielsFro
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
7 years 1 month ago #159238 by DenisChenu
Alternative solution : create an equation question type (1st question in 1st group). ANd put
Code:
{Q1_SQ001=if(empty(Q1_SQ001.NAOK),"NA",Q1_SQ001.NAOK)}
{Q1_SQ002=if(empty(Q1_SQ002.NAOK),"NA",Q1_SQ002.NAOK)}
{Q1_SQ003=if(empty(Q1_SQ003.NAOK),"NA",Q1_SQ003.NAOK)}
See www.limesurvey.org/manual/Expression_Man..._Assignment_Operator

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • NielsFro
  • NielsFro's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 1 month ago #159275 by NielsFro
Dear tpartner, thank you so much for your help! It works just perfectly :) :)

As I have no JavaScrips skills whatsoever, I don't know if the solution you posted here should be added to the workarounds section or if my case is too special to be posted there.

Denis, thanks a lot to you as well!

Best regards
Niels
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose