Welcome to the LimeSurvey Community Forum

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

disable cell

  • delarammahdaviii
  • delarammahdaviii's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 8 months ago #131602 by delarammahdaviii
disable cell was created by delarammahdaviii
hi
how can i do this image ?
i can design like this image but i cant disable unchecked cell
i use JS code for remove unwanted cell , plz help me about showing only checked on Q1-8
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #131606 by tpartner
Replied by tpartner on topic disable cell
Are both questions in the same group? Can you attach a small test survey?

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: delarammahdaviii
The topic has been locked.
  • delarammahdaviii
  • delarammahdaviii's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 8 months ago - 8 years 8 months ago #131608 by delarammahdaviii
Replied by delarammahdaviii on topic disable cell
thank you
my both question in same question group .
Last edit: 8 years 8 months ago by delarammahdaviii.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #131626 by tpartner
Replied by tpartner on topic disable cell
Assuming the questions are sequential, you could add something like this to the source of the first question:

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)');
    var theseQuestions = $(thisQuestion).add(nextQuestion);
 
    // Assign row-specific classes
    $('table.subquestions-list tbody', theseQuestions).each(function(i){
      $('> *', this).each(function(i){
        $(this).addClass('row-'+(i+1)+'');
        $(this).attr('data-row', (i+1));
      });
    });      
    // Assign column-specific classes
    $('table.subquestions-list tr', theseQuestions).each(function(i){
      $('> *', this).each(function(i){
        $(this).addClass('column-'+i+'');
        $(this).attr('data-column', i);
      });
    });  
 
    // Initial Q2 input states
    $('input[type="text"]', nextQuestion).prop('readonly', false).css('opacity', '1');
    // Loop through all un-checked boxes in Q1
    $('input[type="checkbox"]:not(:checked)', thisQuestion).each(function(i) {
      // Disable the corresponding input in Q2
      var rowNum = $(this).closest('tr').attr('data-row');
      var columnNum = $(this).closest('td').attr('data-column');
      $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion).val('').prop('readonly', true).css('opacity', '0.3');
    });
 
    // Listener on the Q1 checkboxes
    $('input[type="checkbox"]', thisQuestion).on('change', function(e) {
      // Reset Q2
      $('input[type="text"]', nextQuestion).prop('readonly', false).css('opacity', '1');
      // Loop through all un-checked boxes in Q1
      $('input[type="checkbox"]:not(:checked)', thisQuestion).each(function(i) {
        // Disable the corresponding input in Q2
        var rowNum = $(this).closest('tr').attr('data-row');
        var columnNum = $(this).closest('td').attr('data-column');
        $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion).val('').prop('readonly', true).css('opacity', '0.3');
      });
    });
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...8_TP.lss
File Size:48 KB

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: delarammahdaviii
The topic has been locked.
  • delarammahdaviii
  • delarammahdaviii's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 8 months ago #131821 by delarammahdaviii
Replied by delarammahdaviii on topic disable cell
thank you tony
how can i apply to 3 question like second question q82
q82,q83,q84 exactly are same
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #131831 by tpartner
Replied by tpartner on topic disable cell
This should work for 3 identical following questions:

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)');
    var nextQuestion2 = $(thisQuestion).nextAll('.array-multi-flexi:eq(1)');
    var nextQuestion3 = $(thisQuestion).nextAll('.array-multi-flexi:eq(2)');
    var theseQuestions = $(thisQuestion).add(nextQuestion).add(nextQuestion2).add(nextQuestion3);
 
    // Assign row-specific classes
    $('table.subquestions-list tbody', theseQuestions).each(function(i){
      $('> *', this).each(function(i){
        $(this).addClass('row-'+(i+1)+'');
        $(this).attr('data-row', (i+1));
      });
    });      
    // Assign column-specific classes
    $('table.subquestions-list tr', theseQuestions).each(function(i){
      $('> *', this).each(function(i){
        $(this).addClass('column-'+i+'');
        $(this).attr('data-column', i);
      });
    });  
 
    // Initial Q2 input states
    $('input[type="text"]', nextQuestion).prop('readonly', false).css('opacity', '1');
    $('input[type="text"]', nextQuestion2).prop('readonly', false).css('opacity', '1');
    $('input[type="text"]', nextQuestion3).prop('readonly', false).css('opacity', '1');
    // Loop through all un-checked boxes in Q1
    $('input[type="checkbox"]:not(:checked)', thisQuestion).each(function(i) {
      // Disable the corresponding input in Q2
      var rowNum = $(this).closest('tr').attr('data-row');
      var columnNum = $(this).closest('td').attr('data-column');
      $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion).val('').prop('readonly', true).css('opacity', '0.3');
      $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion2).val('').prop('readonly', true).css('opacity', '0.3');
      $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion3).val('').prop('readonly', true).css('opacity', '0.3');
    });
 
    // Listener on the Q1 checkboxes
    $('input[type="checkbox"]', thisQuestion).on('change', function(e) {
      // Reset Q2, Q3, Q4
      $('input[type="text"]', nextQuestion).prop('readonly', false).css('opacity', '1');
      $('input[type="text"]', nextQuestion2).prop('readonly', false).css('opacity', '1');
      $('input[type="text"]', nextQuestion3).prop('readonly', false).css('opacity', '1');
      // Loop through all un-checked boxes in Q1
      $('input[type="checkbox"]:not(:checked)', thisQuestion).each(function(i) {
        // Disable the corresponding input in Q2
        var rowNum = $(this).closest('tr').attr('data-row');
        var columnNum = $(this).closest('td').attr('data-column');
        $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion).val('').prop('readonly', true).css('opacity', '0.3');
        $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion2).val('').prop('readonly', true).css('opacity', '0.3');
        $('tr[data-row="'+rowNum+'"] td[data-column="'+columnNum+'"] input[type="text"]', nextQuestion3).val('').prop('readonly', true).css('opacity', '0.3');
      });
    });
    });
</script>

Survey attached:

File Attachment:

File Name: limesurvey...P_v2.lss
File Size:78 KB

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: delarammahdaviii
The topic has been locked.
  • delarammahdaviii
  • delarammahdaviii's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 8 months ago #131910 by delarammahdaviii
Replied by delarammahdaviii on topic disable cell
how can reverse this question
when user click on Q1 , all cell isn't checked and inactive in first question , active in 3rd question until i can ask resan of unchaking ?
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose