hidden multiple choice question for array filter

More
7 years 2 months ago #119183 by marcic
I have been trying to implement the hidden multiple choice question from two single choice question with no luck this far. I have been trying to implement the solutions proposed by tpartner but cannot comprehend the code needed.

Consider I have two questions:

xc06 "Have you smoked during your lifetime?" with 7 options ranging from None to 40+ times
xc07 "How many cigarettes have you smoked during last 30 days?" with 6 options ranging from Not at all to 20+ per day

The xc07 is not shown to those answering psotive to first question.

Then I have computed two hidden equations (eqsm1 for lifetime smokign status and eqsm2 for current smoking) with status 0 indicating nonsmoker and 1 - smoker.

The question I'd like to filter based on these equations is an array with two rows and a number of columns for age when they started smoking.

Once I would have the multiple choice question from those answers in two equations I'd be able to filter the array.

Anybody can assist me with the code for a hidden multiple choice question in such scenario?

Thank you in advance,


Marcis

File Attachment:

File Name: limesurvey...2718.lss
File Size:32 KB
Attachments:
The topic has been locked.
More
7 years 2 months ago - 7 years 2 months ago #119235 by tpartner
Assuming that "xc06" is the first list-radio on the page and "xc07" is the second list-radio on the page, inserting this (somewhat expanded) script in the source of the multiple choice will hide that question and toggle the corresponding check-boxes when "xc06" and "xc07" get a value greater than 1. Array filter does the rest.

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify the questions
		var thisQuestion = $('#question{QID}');
		var radio1 = $('.list-radio:eq(0)');
		var radio2 = $('.list-radio:eq(1)');
 
		// Hide this question
		thisQuestion.hide();
 
		// Listeners on the radios
		$('input.radio', radio1).click(function(e) {
			var checkBox =$('input.checkbox:eq(0)', thisQuestion);
			if(this.value > 1) {
				checkBox.prop('checked', true).next('input[type="hidden"]').attr('value', 'Y');
			}
			else {
				checkBox.prop('checked', false).next('input[type="hidden"]').attr('value', '');
			}
			checkconditions(checkBox.attr('value'), checkBox.attr('name'), checkBox.attr('type'))
		});	
		$('input.radio', radio2).click(function(e) {
			var checkBox =$('input.checkbox:eq(1)', thisQuestion);
			if(this.value > 1) {
				checkBox.prop('checked', true).next('input[type="hidden"]').attr('value', 'Y');
			}
			else {
				checkBox.prop('checked', false).next('input[type="hidden"]').attr('value', '');
			}
			checkconditions(checkBox.attr('value'), checkBox.attr('name'), checkBox.attr('type'))
		});	
	});	
</script>

Sample survey:

File Attachment:

File Name: limesurvey...7181.lss
File Size:33 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 7 years 2 months ago by tpartner.
The topic has been locked.
More
7 years 2 months ago #119450 by marcic
Thank you tpartner. But do you think is there a way that this can be implemented as question-by-question?

Best,

Marcis
The topic has been locked.
More
7 years 2 months ago #119458 by tpartner
No, you won't be able to use a hidden multiple- choice in question-by-question mode.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now