Hide last 3 rows of an array question

More
5 months 2 weeks ago #170752 by paulfiner
paulfiner created the topic: Hide last 3 rows of an array question
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

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago - 5 months 1 week ago #170755 by tpartner
tpartner replied the topic: Hide last 3 rows of an array question
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.
Last Edit: 5 months 1 week ago by tpartner.
The following user(s) said Thank You: DenisChenu

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago - 5 months 1 week ago #170773 by paulfiner
paulfiner replied the 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 months 1 week ago by paulfiner. Reason: spelling

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago #170796 by paulfiner
paulfiner replied the 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?

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago #170797 by tpartner
tpartner replied the 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:
<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.
Attachments:
The following user(s) said Thank You: DenisChenu

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago #170799 by paulfiner
paulfiner replied the topic: Hide last 3 rows of an array question
That's great! Works perfectly.

Thanks for your help Tony.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!