Welcome to the LimeSurvey Community Forum

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

Hide last 3 rows of an array question

  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 8 months ago #170752 by paulfiner
Hide last 3 rows of an array question was created by paulfiner
I have a standard array question with 6 sub-questions that are randomised. I would like to hide the last 3 rows of the table so the respondent effectively sees 3 random sub-questions out of 6.
I'm sure the javascript for this is fairly simple but I'm struggling!

Thanks

Limesurvey v2.55
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago - 5 years 8 months ago #170755 by tpartner
Replied by tpartner on topic Hide last 3 rows of an array question
[strike]You don't need JS for that. You can do it with sub-question relevance, counting the relevance status of other sub-questions.[/strike]

[EDIT]Further testing indicates that this does not work consistently[/EDIT]

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 8 months ago by tpartner.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 8 months ago - 5 years 8 months ago #170773 by paulfiner
Replied by paulfiner on topic Hide last 3 rows of an array question
Hi Tony,
Thanks for your reply and the sample survey. I tried this but it only ever shows the first 3 sub-question codes.
I need it to randomly show 3 of the 6 possible options - sorry if I didn't explain that originally.
Thanks
Last edit: 5 years 8 months ago by paulfiner. Reason: spelling
The topic has been locked.
  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 8 months ago #170796 by paulfiner
Replied by paulfiner on topic Hide last 3 rows of an array question
In V2.55 I was only getting codes 1-3 randomized.
What would be the javascript code to hide row 4 of the table in an Array question?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #170797 by tpartner
Replied by tpartner on topic Hide last 3 rows of an array question
Oh, yes, I see. I did not test thoroughly enough.

In that case, to allow for a "mandatory" setting, I would...

1) Insert a hidden (via CSS class) multiple choice question before the array with randomized sub-questions.

2) Add this script to the multiple-choice which will check the first 3 boxes:
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var thisQuestion = $('#question{QID}');
 
    // Check first 3 options (but only if page has not been visited) 
    if($('input:checkbox:checked', thisQuestion).length == 0) {
      $('input:checkbox:lt(3)', thisQuestion).each(function(i) {
        $(this).prop('checked', true);
        $(this).nextAll('input:hidden:eq(0)').val('Y');
        checkconditions(this.value, this.name, this.type);
      });
    }
    });
</script>

3) Place an array filter on the array so only rows checked in the hidden question will be shown (and relevant).

Sample survey attached:

File Attachment:

File Name: limesurvey...8982.lss
File Size:24 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: DenisChenu
The topic has been locked.
  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 8 months ago #170799 by paulfiner
Replied by paulfiner on topic Hide last 3 rows of an array question
That's great! Works perfectly.

Thanks for your help Tony.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose