Welcome to the LimeSurvey Community Forum

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

Array filter between Scale 1 and Scale 2 in Dual Matrix - with Dropdown-Menue

  • Ryuniri_44052
  • Ryuniri_44052's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
9 years 6 months ago #118881 by Ryuniri_44052
Hey Lemons,

Some weeks ago I ask in this forum how to set an array filter between scale 1 and scale 2 in a dual matrix and got perfect help:

Array filter between Scale 1 and Scale 2 in Dual Matrix

Now I would like to do the same with a dual matrix with dropdown menues. I tried to adjust the script, but without success. Can you please tell me, if it is possible to disable the dropdown menue in scale 2 dependendly from the answer in scale 1?

I want to disable the second scale if the participant chooses the last option in the dropdown menue in scale 1. To set the second menue to a given answer dependently from the choice in scale 1 is also fine.

Thank you very much!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 6 months ago - 9 years 6 months ago #118887 by tpartner
Placing this script in the question source will result in the following behaviour:
- When selecting the last option in a scale-1 drop-down, the scale-2 drop-down in that row will also be set to its last option and disabled.
- Selecting any but the last option in a scale-1 drop-down will enable the scale-2 drop-down in that row.

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Assign classes
    $('tr.subquestion-list', thisQuestion).each(function(i){
      $('td.answer-item', this).each(function(i){
        $(this).addClass('scale-'+(i+1));
      });
    });
 
    // Some vars...
    var excludeValue1 = $('td.answer-item:eq(0) option:last', thisQuestion).attr('value');
    var excludeValue2 = $('td.answer-item:eq(1) option:last', thisQuestion).attr('value');
 
    // Listener on the dropdowns
    $('.scale-1 select', thisQuestion).change(function(e) {
      var thisRow = $(this).closest('tr');
      if($(this).val() == excludeValue1) {
        $('.scale-2 select', thisRow).val(excludeValue2).prop('disabled', true);
      }
      else if($('.scale-2 select', thisRow).is(':disabled')){
        $('.scale-2 select', thisRow).prop('disabled', false);
      }
    });
 
    // Initial states
    $('.scale-1 select', thisQuestion).each(function(i) {
      var thisRow = $(this).closest('tr');
      if($(this).val() == excludeValue1) {
        $('.scale-2 select', thisRow).val(excludeValue2).prop('disabled', true);
      }
    });
 
    // Remove any "disabled" properties befor submitting
    $('#movenextbtn, #movesubmitbtn').bind('click', function () {      
      $('select', thisQuestion).prop('disabled', false);
    });
 
    });  
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 6 months ago by tpartner.
The following user(s) said Thank You: Ryuniri_44052
The topic has been locked.
  • Ryuniri_44052
  • Ryuniri_44052's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
9 years 6 months ago #118892 by Ryuniri_44052
Thank you! This is all I ever want! It works perfectly.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose