Welcome to the LimeSurvey Community Forum

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

How to make an answer option 'unclickable'?

  • hanwerts
  • hanwerts's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 7 months 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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #139583 by tpartner
Replied by tpartner on topic How to make an answer option 'unclickable'?
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.
  • hanwerts
  • hanwerts's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 7 months ago #139585 by hanwerts
Replied by hanwerts on topic How to make an answer option 'unclickable'?
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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #139590 by tpartner
Replied by tpartner on topic How to make an answer option 'unclickable'?
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:23 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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago - 7 years 7 months ago #139593 by tpartner
Replied by tpartner on topic How to make an answer option 'unclickable'?
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 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 7 months ago by tpartner.
The topic has been locked.
  • hanwerts
  • hanwerts's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 7 months ago #139703 by hanwerts
Replied by hanwerts on topic How to make an answer option 'unclickable'?
Great! It works :woohoo: . Many, many thanks for your quick and outstanding help!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose