Welcome to the LimeSurvey Community Forum

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

Disable specific boxes (=answer options) in a array question (numbers)

More
5 years 4 months ago #196691 by tpartner
Can you please provide a screenshot/mockup and a small sample survey (.lss file) containing only the relevant question?

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: zserban
The topic has been locked.
More
5 years 4 months ago #196706 by zserban

tpartner wrote: Can you please provide a screenshot/mockup and a small sample survey (.lss file) containing only the relevant question?



Hi tpartner, thank you for taking the time!

I inserted the code I found here in the array question.

It does the job (hiding the row 4 and 12 for answer 6. These rows correspond to subquestions 4 and 12, which shouldn't be answered by option 6.), but the random - which is a must - is messing it up.
The topic has been locked.
More
5 years 4 months ago #196719 by holch
Any specific reason why you zipped the LSS file?

You can upload it directly to the forum. One step less for Tpartner to help you.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The following user(s) said Thank You: zserban
The topic has been locked.
More
5 years 4 months ago #196721 by zserban
Oh, out of habbit.


Also, forgot to mention, is Limesurvey 3 branch (the latest public release)
The topic has been locked.
More
5 years 4 months ago - 5 years 4 months ago #196740 by tpartner
You can target the rows with the sub-question codes like this:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Remove row 4, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').remove();
 
    // Remove row 12, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').remove();
  });  
</script>

This part of the selector - tr.answers-list[id$="X{QID}12"] - effectively says "row with ID ending in X + Question ID + SQ Code 12".

Sample survey attached:

File Attachment:

File Name: limesurvey...4431.lss
File Size:47.26 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 4 months ago by tpartner.
The following user(s) said Thank You: zserban
The topic has been locked.
More
5 years 4 months ago #196744 by zserban

tpartner wrote: You can target the rows with the sub-question codes like this:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Remove row 4, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').remove();
 
    // Remove row 12, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').remove();
  });  
</script>

This part of the selector - tr.answers-list[id$="X{QID}12"] - effectively says "row with ID ending in X + Question ID + SQ Code 12".

Sample survey attached:

File Attachment:

File Name: limesurvey...4431.lss
File Size:47.26 KB



It works very well! I really appreciate it (and others will do too), tpartner.

No doubt, in a similar fashion, you can even filter available answers by responses given at previous questions, something that cannot be done out of the box. This might be quite handy because it could shorten the total number of questions a respondent has to answer.
The topic has been locked.
More
4 years 4 months ago #214255 by batpurev
hi all,

Does anyone know how to disable an Array element and show some Sum of other elements of the same array? (Question type: Array (Texts) 

thanks in advance.
The topic has been locked.
More
4 years 4 months ago #214256 by batpurev
Based on posts on this thread I tried followings but none seems to work.

<script type="text/javascript" charset="utf-8">
   $(document).ready(function() {
        $('array-multi-flexi[id="q1_x1_y1"]').attr('disabled', 'disabled');
        $('array[id="q1_x1_y1"]').attr('disabled', 'disabled');
        $('input[name="q1_x1_y1"]').hide();
       $('array-multi-flexi[name="q1_x1_y1"]').hide();
       $('input[name="#answertextq1_x1_y1"]').attr('disabled', 'disabled');
   });
 </script>

The topic has been locked.
More
4 years 4 months ago #214259 by batpurev
Found solution to my question below is my code if anyone faces similar issue.

<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('input[id="answer752589X30X2319x1_y1"]').attr('disabled', 'disabled');});
    
    $("#limesurvey").on("change", function(event) { 
         var k = parseFloat($('input[id="answer752589X30X2319x2_y1"]').val());
         var l = parseFloat($('input[id="answer752589X30X2319x3_y1"]').val());
         var m = k+l;
         $('input[id="answer752589X30X2319x1_y1"]').val(m);
});
</script>

The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose