- Posts: 10
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
hidden multiple choice question for array filter
- marcic
- Topic Author
- Offline
- New Member
Less
More
9 years 1 week ago #119183
by marcic
hidden multiple choice question for array filter was created 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
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
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
9 years 1 week ago - 9 years 1 week ago #119235
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic hidden multiple choice question for array filter
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.
Sample survey:
Code:
<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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 9 years 1 week ago by tpartner.
The topic has been locked.
- marcic
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 1
9 years 3 days ago #119450
by marcic
Replied by marcic on topic hidden multiple choice question for array filter
Thank you tpartner. But do you think is there a way that this can be implemented as question-by-question?
Best,
Marcis
Best,
Marcis
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
9 years 3 days ago #119458
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic hidden multiple choice question for array filter
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.