- Posts: 61
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Filtering sub questions in a prefiltered array
- achecchini
- Topic Author
- Offline
- Senior Member
Less
More
9 years 6 months ago #114064
by achecchini
Filtering sub questions in a prefiltered array was created by achecchini
Because of my poor knowledge on javascript I have problem to solve the following:
I have a multiple-selection question ie:
question 1
[] Option a
[] Option b
[] Option c
[] Option d
The next question (radiobuttons) is filtered by the Question 1 responses, ie:
question 2
1 2 3 4 5
option a () (x) () () ()
Option b () () () () (x)
I want the next question 3 shows the results ONLY if the answer to question 2 has a value less or equal than = 2 ie:
question 3
Factor X Factor Y
1 2 3 4 1 2 3 4
option a ()()()() ()()()()
Note that the last question is an array dual scale. If I filter by question 2 response I see all checked responses and not only the =< of 2
I've not found on the forum (or I am not able tofound :blink: ) Jscript suitable to my needs
Can someone help me ??
Thank you very much
I have a multiple-selection question ie:
question 1
[] Option a
[] Option b
[] Option c
[] Option d
The next question (radiobuttons) is filtered by the Question 1 responses, ie:
question 2
1 2 3 4 5
option a () (x) () () ()
Option b () () () () (x)
I want the next question 3 shows the results ONLY if the answer to question 2 has a value less or equal than = 2 ie:
question 3
Factor X Factor Y
1 2 3 4 1 2 3 4
option a ()()()() ()()()()
Note that the last question is an array dual scale. If I filter by question 2 response I see all checked responses and not only the =< of 2
I've not found on the forum (or I am not able tofound :blink: ) Jscript suitable to my needs
Can someone help me ??
Thank you very much
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10117
- Thank you received: 3597
9 years 6 months ago #114090
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 Filtering sub questions in a prefiltered array
Here's a post that may help -
www.limesurvey.org/en/forum/can-i-do-thi...estion-result#112088
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- achecchini
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 61
- Thank you received: 0
9 years 6 months ago #114122
by achecchini
Replied by achecchini on topic Filtering sub questions in a prefiltered array
Thanks so much for the suggestion! It's very close to my problem.
I have found, suitable for my problem, also this discussion:https://www.limesurvey.org/en/forum/can-i-do-this-with-limesurvey/58002-using-previous-array-question-responses-to-set-following-array-subquestions?q=/en/forum/can-i-do-this-with-limesurvey/58002-using-previous-array-question-responses-to-set-following-array-subquestions&start=40
But there is a problem. If I manipulating the checks box checking and unchecking the radiobutton i.e. check the 1 & 2 column and then check the column 4-5-6 etc repeating this two or three times the filter break in functioning.
I try to understand the problem, but for now I hadn't found a solution ...
Thanks a lot for help!!
A.
I have found, suitable for my problem, also this discussion:https://www.limesurvey.org/en/forum/can-i-do-this-with-limesurvey/58002-using-previous-array-question-responses-to-set-following-array-subquestions?q=/en/forum/can-i-do-this-with-limesurvey/58002-using-previous-array-question-responses-to-set-following-array-subquestions&start=40
But there is a problem. If I manipulating the checks box checking and unchecking the radiobutton i.e. check the 1 & 2 column and then check the column 4-5-6 etc repeating this two or three times the filter break in functioning.
I try to understand the problem, but for now I hadn't found a solution ...
Thanks a lot for help!!
A.
The topic has been locked.
- achecchini
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 61
- Thank you received: 0
9 years 6 months ago #114140
by achecchini
Replied by achecchini on topic Filtering sub questions in a prefiltered array
To explane better my problem I attach an example.
The matter is this: when I uncheck one of the radio button in column 1-2 (checking on column 3-4-5 etc.) the corrispondent filtered row in Q2 disappear, BUT if I check another time the radiobutton under column 1-2 in Q1 the filtered corrispondent row in Q2 don't appear.
Any help it's very appreciate
Thanks in advance
A.
The matter is this: when I uncheck one of the radio button in column 1-2 (checking on column 3-4-5 etc.) the corrispondent filtered row in Q2 disappear, BUT if I check another time the radiobutton under column 1-2 in Q1 the filtered corrispondent row in Q2 don't appear.
Any help it's very appreciate
Thanks in advance
A.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10117
- Thank you received: 3597
9 years 6 months ago #114166
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 Filtering sub questions in a prefiltered array
Replace this line in your script:
with this:
So, the whole script:
Code:
$(hiddenInput).attr('checked', checkedState);
with this:
Code:
$(hiddenInput).prop('checked', checkedState);
So, the whole script:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the function countChecked('{SGQ}'); function countChecked(sgq) { // Identify the questions var sID = sgq.split('X')[0]; var gID = sgq.split('X')[1]; var qHiddenID = sgq.split('X')[2]; var qHidden = $('#question'+qHiddenID+''); if($(qHidden).length > 0) { var q1 = $(qHidden).prevAll('.array-flexible-row:eq(0)'); var q1ID = $(q1).attr('id').split('question')[1]; var q2 = $(qHidden).nextAll('.array-flexible-row:eq(0)'); var q2ID = $(q2).attr('id').split('question')[1]; } // Hide the hidden question $('#question'+qHiddenID+'').hide(); // Assign column-specific classes to Q1 $('.answers-list', q1).each(function(i){ $('td.answer-item', this).each(function(i){ $(this).addClass('answer-column-'+(i+1)+''); }); }); // A listener on the 1st column of Q1 radio buttons $('.answer-column-1, .answer-column-2', q1).click(function () { handleHiddenInput (this, 'checked'); }); // A listener on the 2nd and 3rd columns of Q1 radio buttons $('.answer-column-3, .answer-column-4, .answer-column-5, .answer-column-6, .answer-column-7', q1).click(function () { handleHiddenInput (this, 'unchecked'); }); // A function to toggle the hidden checkboxes function handleHiddenInput(trigger, state) { // Identify some stuff var rowID = $(trigger).closest('tr.answers-list').attr('id'); var tmp = rowID.split('X'+q1ID); var answerCode = tmp[1]; var hiddenInput = $('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode); // Toggle the input depending on "state" var checkedState = false; if(state == 'checked') { checkedState = true; } $(hiddenInput).prop('checked', checkedState); // Fire the conditions function to hide the corresponding row in Q2 var hiddenInputValue = $(hiddenInput).attr('value'); var hiddenInputName = $(hiddenInput).attr('name'); var hiddenInputType = $(hiddenInput).attr('type'); checkconditions(hiddenInputValue, hiddenInputName, hiddenInputType); // Fix up the q2 row background colours $('.answers-list:visible', q2).each(function(i, el){ $(el).removeClass('array1, array2'); if(i % 2 == 0) { $(el).addClass('array2'); } else { $(el).addClass('array1'); } }); } } }); </script>
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: achecchini
The topic has been locked.
- achecchini
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 61
- Thank you received: 0
9 years 6 months ago #114168
by achecchini
Replied by achecchini on topic Filtering sub questions in a prefiltered array
**** SOLVED !!!! ****
Perfect!! Now it's perfectly functioning. A huge thanks for helping !!
Perfect!! Now it's perfectly functioning. A huge thanks for helping !!
The topic has been locked.
- envitera
- Offline
- Junior Member
Less
More
- Posts: 20
- Thank you received: 0
9 years 6 months ago #114170
by envitera
Replied by envitera on topic Filtering sub questions in a prefiltered array
This also works when questions are not in the same group. Everything is done by expression manager, except of 3 lines of code in the question needed for filtering.
In this case the question used for filtering is a multi numerical question where the fields are set or unset with expressions similar to this:
It's a kind of subquestion relevance solution proposed in this post and with a bit of handiwork you can apply it to different types of questions I guess.
Code:
<script type="text/javascript" charset="utf-8"> $('#question{QID}').hide(); </script>
In this case the question used for filtering is a multi numerical question where the fields are set or unset with expressions similar to this:
Code:
{if(Q1_1.NAOK=='A1' OR Q1_1.NAOK=='A2',1,'')}
It's a kind of subquestion relevance solution proposed in this post and with a bit of handiwork you can apply it to different types of questions I guess.
Attachments:
The topic has been locked.