- Posts: 10110
- Thank you received: 3593
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array filter with exclusive option
- tpartner
- Away
- LimeSurvey Community Team
Less
More
13 years 7 months ago - 13 years 7 months ago #48429
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 Array filter with exclusive option
Okay, so if anyone still cares, Dawna and I finally sorted it out. The main hurdles were that she was randomizing the answers of the filtered questions, using the "Other" option for every question and that she wanted the last 2 options to be "sticky".
So the final code is as follows (where the "Other" options are inserted with the LimeSurvey interface and the question code for "None of the above" is 98).
Phew!!!
So the final code is as follows (where the "Other" options are inserted with the LimeSurvey interface and the question code for "None of the above" is 98).
Phew!!!
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Find the survey, group and question IDs if($( 'input#fieldnames' ).length != 0) { var fieldNames = $('input#fieldnames').attr('value'); var tmp = fieldNames.split('X'); var sID = tmp[0]; var gID = tmp[1]; var qIDStr = $('div.multiple-opt:eq(0)').attr('id'); var tmp2 = qIDStr.split('question'); var qID = tmp2[1]; } // Place the "None of the above" option second last after randomization $('li#javatbd'+sID+'X'+gID+'X'+qID+'98').insertBefore($('.survey-question-answer li:last')); // Set an index for the second last option var itemCount = $('.survey-question-answer li').length; itemIndex = Number(itemCount-2); // Show the last two options window.setTimeout(function() { $('.survey-question-answer li:eq('+itemIndex+')').show(); $('.survey-question-answer li:eq('+itemIndex+') input[type=hidden]:eq(0)').attr('value', 'on'); $('.survey-question-answer li:last').show(); $('.survey-question-answer li:last input[type=hidden]:eq(0)').attr('value', 'on'); }, 50); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 13 years 7 months ago by tpartner.
The topic has been locked.
- arielmosto
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
13 years 1 month ago - 13 years 1 month ago #58665
by arielmosto
Replied by arielmosto on topic Array filter with exclusive option
Thank you very much. I'm using this script without problems in Firefox and Chrome but crashes in Internet Explorer. I, housed several hours but not how to make it work in IE.
I am using the first script you post:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
window.setTimeout(function(){
$('td.answer li:last').show();
$('td.answer li:last input[type=hidden]:eq(0)').attr('value', 'on');
}, 50);
});</script>
Thanks in advance for your help. Ariel
I am using the first script you post:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
window.setTimeout(function(){
$('td.answer li:last').show();
$('td.answer li:last input[type=hidden]:eq(0)').attr('value', 'on');
}, 50);
});</script>
Thanks in advance for your help. Ariel
Last edit: 13 years 1 month ago by arielmosto.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
13 years 1 month ago #58667
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 Array filter with exclusive option
Are you getting any JavaScript errors?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- arielmosto
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
13 years 1 month ago #58668
by arielmosto
Replied by arielmosto on topic Array filter with exclusive option
Attachments:
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
13 years 1 month ago #58669
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 Array filter with exclusive option
I think you have an error in another script preventing mine from running - I do not use "document.getElementById".
Can you activate a sample survey for us to test?
Can you activate a sample survey for us to test?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- arielmosto
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
13 years 1 month ago #58670
by arielmosto
Replied by arielmosto on topic Array filter with exclusive option
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
13 years 1 month ago #58696
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 Array filter with exclusive option
I see no JS errors and the script appears to work in both Firefox and IE.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- arielmosto
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
13 years 1 month ago #58716
by arielmosto
Replied by arielmosto on topic Array filter with exclusive option
Thank you very much Tony. I did the sample from Ubuntu and I could not test Internet Explorer to realize that it was working perfect. Then delete the questions that did not work in the original survey, we did back and now everything works correctly in FF, Chrome, IE 6, IE 7 and IE 8. Thank you very much for your help! Ariel
The topic has been locked.
- dknvs
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
9 years 10 months ago #110285
by dknvs
Replied by dknvs on topic Array filter with exclusive option
Hi, Tony
I have a similar issue but the codes that are posted in the forum don't seem to work for my case. I am wondering if you could help me with ediiting the JS codes?
So here is the background for the survey:
We have two multiple select questions. what i select for Q1 will pipe for Q2. People who select "don't know" at Q1 won't see Q2.However, i would like to show "Don't know" for Q2. For the current setting right now, "Don't know" and "Other, please specify" are not showing.
Question 1 (Code Q1) (multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
DK Don't know (exclusion option)
**Exclusion option:DK
Question2 (Code Q2) (another multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
Other, please specify
DK Don't know (exclusion option)
**Relevance equation:
((Q1_1.NAOK == "Y" or Q1_2.NAOK == "Y" or Q1_3.NAOK == "Y"))
**Array filter: Q1
**Exclusion option: DK
Thank you so much!
Vicky
I have a similar issue but the codes that are posted in the forum don't seem to work for my case. I am wondering if you could help me with ediiting the JS codes?
So here is the background for the survey:
We have two multiple select questions. what i select for Q1 will pipe for Q2. People who select "don't know" at Q1 won't see Q2.However, i would like to show "Don't know" for Q2. For the current setting right now, "Don't know" and "Other, please specify" are not showing.
Question 1 (Code Q1) (multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
DK Don't know (exclusion option)
**Exclusion option:DK
Question2 (Code Q2) (another multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
Other, please specify
DK Don't know (exclusion option)
**Relevance equation:
((Q1_1.NAOK == "Y" or Q1_2.NAOK == "Y" or Q1_3.NAOK == "Y"))
**Array filter: Q1
**Exclusion option: DK
Thank you so much!
Vicky
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
9 years 10 months ago #110289
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 Array filter with exclusive option
If I understand the requirements correctly, this should do the trick. Use a different code for "Don't know" in Q2 and a slightly different relevance equation for Q2.
Question 1 (Code Q1) (multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
DK Don't know (exclusion option)
**Exclusion option:DK
Question2 (Code Q2) (another multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
DK2 Don't know (exclusion option)
Other, please specify
**Relevance equation: Q1_DK != 'Y'
**Array filter: Q1
**Exclusion option: DK2
.
Question 1 (Code Q1) (multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
DK Don't know (exclusion option)
**Exclusion option:DK
Question2 (Code Q2) (another multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
DK2 Don't know (exclusion option)
Other, please specify
**Relevance equation: Q1_DK != 'Y'
**Array filter: Q1
**Exclusion option: DK2
.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- dknvs
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
9 years 10 months ago #110290
by dknvs
Replied by dknvs on topic Array filter with exclusive option
Hi, Tony
thanks for your fast reply.
for our calculation on the site, the "DK" code is set if we want to exclude that from the calculation.
Would there be a way for me to keep that code?
thanks
Vicky
thanks for your fast reply.
for our calculation on the site, the "DK" code is set if we want to exclude that from the calculation.
Would there be a way for me to keep that code?
thanks
Vicky
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
9 years 10 months ago #110292
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 Array filter with exclusive option
No, that will tie it to the array filter from Q1. The array filters work on sub-question codes.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.