Welcome to the LimeSurvey Community Forum

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

Dual Scale -- set second scale based on selection in first?

More
5 years 6 months ago #213062 by blocka
I have a dual scale, where the selection of N/A in the first scale needs to force N/A to be selected in the 2nd array (and ideally disable the other options in the 2nd scale).

I've attached a sample survey with the dual scale question.

 

File Attachment:

File Name: survey_183285.lss
File Size:23.32 KB
The topic has been locked.
More
5 years 6 months ago - 5 years 6 months ago #213064 by Joffm
This is somewhere here in the forum.
 
Code:
<script type="text/javascript" charset="utf-8">     $(document).on('ready pjax:scriptcomplete',function(){           // Identify this question         var thisQuestion = $('#question{QID}');           // Identify the "exclusive" answer(s) in scale one         // Multiple answer separated by commas are possible         var exclusiveValues = ['A3'];                  // Hide the "N/A" option in scale 2         // Set this to false if you want that option always visible         var hideNA = true;                  // Identify the "N/A" value in scale 2         var naValue = $('select[id$="_1"]:eq(0) option:last', thisQuestion).attr('value');                  // A funstion to handle the drop-down behaviour         function handleSelects(thisSelect) {             var selectVal = $(thisSelect).val();             var thisRow = $(thisSelect).closest('tr');             var exclusive = false;             $.each(exclusiveValues, function(i, val) {                 if(selectVal == val) {                     exclusive = true;                 }             });             if(exclusive == true) {                 if(hideNA == true) {                     $('select[id$="_1"] option[value="'+naValue+'"]', thisRow).toggleOption(true);                 }                                 $('select[id$="_1"]', thisRow).val(naValue).prop('disabled', true);             }             else {                 $('select[id$="_1"]', thisRow).prop('disabled', false);                 if(hideNA == true) {                     $('select[id$="_1"] option[value="'+naValue+'"]', thisRow).toggleOption(false);                 }                             }         }           // Listener on the drop-downs         $('select[id$="_0"]', thisQuestion).on('change', function(e) {             handleSelects($(this));         });           // Initial states         $('select[id$="_0"]', thisQuestion).each(function(i) {             handleSelects($(this));         });                  // On submit         $('#ls-button-submit').on('click', function(e) {             $('select[id$="_1"]', thisQuestion).prop('disabled', false);         });     });              $.fn.toggleOption = function(show) {         jQuery(this).toggle(show);         if(show) {             if( jQuery(this).parent('span.toggleOption').length)                 jQuery(this).unwrap();         } else {             if(jQuery(this).parent('span.toggleOption' ).length == 0)                 jQuery(this).wrap( '<span class="toggleOption" style="display: none;" />');         }     }; </script>

With your survey
 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 years 6 months ago by Joffm.
The following user(s) said Thank You: blocka
The topic has been locked.
More
5 years 6 months ago #213065 by blocka
I found this post -- but it is very old and don't think it would apply to latest LS 3.x version...

forums.limesurvey.org/forum/can-i-do-thi...e-based-on-the-other
The topic has been locked.
More
5 years 6 months ago #213068 by blocka
A thing of beauty! Thank you.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose