Welcome to the LimeSurvey Community Forum

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

How to make an answer option 'unclickable'?

More
9 years 1 month ago #139578 by hanwerts
Hi,

I have a question on the array option in Lime Survey. As you can see in the attachment, I have an array in the first question with one possible answer option per row (means of transportation in Dutch). In the second question, I want to ask, again per day (!), whether the respondents also make use of other means of transportation. Therefore, I want the option they selected in question 1 to be NOT clickable.

Is that possible. And if yes, how? Thank you!
The topic has been locked.
More
9 years 1 month ago #139583 by tpartner
Are both questions on the same page?
LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 1 month ago #139585 by hanwerts
Dear tpartner, thank you!

The questions are indeed on the same page... and version is 2.05+. Hope you can help me B)
The topic has been locked.
More
9 years 1 month ago #139590 by tpartner
Add this script to the source of the first array:

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify the questions
    var thisQuestion = $('#question{QID}');
    var nextQuestion = $(thisQuestion).nextAll('.array-multi-flexi:eq(0)');
 
    // Listener on the radios
    $('input.radio', thisQuestion).on('click', function(e) {
      // Find the clicked radio row and column index
      var thisRow = $(this).closest('tr');
      var thisColumn = $(this).closest('td');
      var thisRowIndex = $('tr.answers-list', $(this).closest('tbody')).index(thisRow);
      var thisColumnIndex = $('td.answer-item', $(this).closest('tr')).index(thisColumn);
 
      // Disable and un-check the corresponding checkbox in the following question
      var nextQuestionRow = $('tr.subquestions-list:eq('+thisRowIndex+')', nextQuestion);
      var nextQuestionCell = $('td.answer-item:eq('+thisColumnIndex+')', nextQuestionRow);
      $('input.checkbox', nextQuestionRow).prop('disabled', false);
      $('input.checkbox', nextQuestionCell).prop('checked', false).prop('disabled', true);
      $('input:hidden', nextQuestionCell).attr('value', '');
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...44-2.lss
File Size:22.54 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 1 month ago - 9 years 1 month ago #139593 by tpartner
Oops, forgot to handle things if a respondent returns to the group - use this instead:

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify the questions
    var thisQuestion = $('#question{QID}');
    var nextQuestion = $(thisQuestion).nextAll('.array-multi-flexi:eq(0)');
 
    // Initial states
    // Loop through all clicked radios
    $('input.radio:checked', thisQuestion).each(function(i) {
      // Find the clicked radio row and column index
      var thisRow = $(this).closest('tr');
      var thisColumn = $(this).closest('td');
      var thisRowIndex = $('tr.answers-list', $(this).closest('tbody')).index(thisRow);
      var thisColumnIndex = $('td.answer-item', $(this).closest('tr')).index(thisColumn);
 
      // Disable the corresponding checkbox in the following question
      var nextQuestionRow = $('tr.subquestions-list:eq('+thisRowIndex+')', nextQuestion);
      var nextQuestionCell = $('td.answer-item:eq('+thisColumnIndex+')', nextQuestionRow);
      $('input.checkbox', nextQuestionCell).prop('disabled', true);
    });
 
    // Listener on the radios
    $('input.radio', thisQuestion).on('click', function(e) {
      // Find the clicked radio row and column index
      var thisRow = $(this).closest('tr');
      var thisColumn = $(this).closest('td');
      var thisRowIndex = $('tr.answers-list', $(this).closest('tbody')).index(thisRow);
      var thisColumnIndex = $('td.answer-item', $(this).closest('tr')).index(thisColumn);
 
      // Disable and un-check the corresponding checkbox in the following question
      var nextQuestionRow = $('tr.subquestions-list:eq('+thisRowIndex+')', nextQuestion);
      var nextQuestionCell = $('td.answer-item:eq('+thisColumnIndex+')', nextQuestionRow);
      $('input.checkbox', nextQuestionRow).prop('disabled', false);
      $('input.checkbox', nextQuestionCell).prop('checked', false).prop('disabled', true);
      $('input:hidden', nextQuestionCell).attr('value', '');
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...1)-2.lss
File Size:24.12 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 1 month ago by tpartner.
The topic has been locked.
More
9 years 1 month ago #139703 by hanwerts
Great! It works :woohoo: . Many, many thanks for your quick and outstanding help!
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose