Hide last 3 rows of an array question

More
2 years 1 month ago #170752 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.
LimeSurvey Partners
More
2 years 1 month ago - 2 years 1 month ago #170755 by tpartner
You don't need JS for that. You can do it with sub-question relevance, counting the relevance status of other sub-questions.

[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.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 2 years 1 month ago by tpartner.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
More
2 years 1 month ago - 2 years 1 month ago #170773 by paulfiner
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: 2 years 1 month ago by paulfiner. Reason: spelling
The topic has been locked.
More
2 years 1 month ago #170796 by paulfiner
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.
More
2 years 1 month ago #170797 by tpartner
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:
<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.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
The following user(s) said Thank You: DenisChenu
The topic has been locked.
More
2 years 1 month ago #170799 by paulfiner
That's great! Works perfectly.

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

Start now!

Just create your account and start using Limesurvey today.

Register now