- Posts: 6
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
For Multiple Choice Questions, can the sub questions takes x out of y answer
- etc4xx
- Topic Author
- Offline
- New Member
Less
More
4 years 2 months ago #193751
by etc4xx
For Multiple Choice Questions, can the sub questions takes x out of y answer was created by etc4xx
Hello All
Need assistance to with regards to the Multiple choice type questions.
Can i select x numbers of subquestions, that is taken from a pool of y numbers of subquestion?
It is similar with the issues in the link provided, but instead of questions, can we do this with subquestions in multiple choice type questions as well.
www.limesurvey.org/forum/can-i-do-this-w...s-from-a-bucket-of-y
Thank you
Regards
Need assistance to with regards to the Multiple choice type questions.
Can i select x numbers of subquestions, that is taken from a pool of y numbers of subquestion?
It is similar with the issues in the link provided, but instead of questions, can we do this with subquestions in multiple choice type questions as well.
www.limesurvey.org/forum/can-i-do-this-w...s-from-a-bucket-of-y
Thank you
Regards
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12937
- Thank you received: 3979
4 years 2 months ago - 4 years 2 months ago #193760
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic For Multiple Choice Questions, can the sub questions takes x out of y answer
How many of how many?
I ask this because I have two solutions for that.
The straightforward one and a javascript solution.
Joffm
Here the javascript example for 10 out of 50.
You see the places (10, 51) where you have to adapt it.
Joffm
By the way, the example also shows this for a multiple numeric input question.
I ask this because I have two solutions for that.
The straightforward one and a javascript solution.
Joffm
Here the javascript example for 10 out of 50.
Code:
<script type="text/javascript" charset="utf-8"> function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } $(document).on('ready pjax:scriptcomplete',function(){ // Fill the array var arr = []; for (var i = 1; i < 51; i++) { arr.push(i); } arr = shuffle(arr); anumbers = arr.slice(0,10).join(','); $('#question{QID} input[type="text"]').val("#,"+anumbers+","); $('#question{QID}').hide(); }); </script>
You see the places (10, 51) where you have to adapt it.
Joffm
By the way, the example also shows this for a multiple numeric input question.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 2 months ago by Joffm.
The following user(s) said Thank You: etc4xx
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 years 2 months ago - 4 years 2 months ago #193765
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 For Multiple Choice Questions, can the sub questions takes x out of y answer
Another JavaScript solution...
- Place a multiple-choice question with the same sub-questions before your question.
- Randomize the sub-questions in the new question.
- Hide the new question with a CSS class "hidden".
- Place an array filter on your question based on the new question.
- Insert the script below in the new question. It will check the first "numberToShow" of sub-questions in the hidden question causing the corresponding sub-qustions to be shown in your question.
Sample survey attached:
- Place a multiple-choice question with the same sub-questions before your question.
- Randomize the sub-questions in the new question.
- Hide the new question with a CSS class "hidden".
- Place an array filter on your question based on the new question.
- Insert the script below in the new question. It will check the first "numberToShow" of sub-questions in the hidden question causing the corresponding sub-qustions to be shown in your question.
Code:
<script type="text/javascript" charset="utf-8"> var numberToShow = 5; $(document).on('ready', function(){ if($('#question{QID} input:checkbox:checked').length == 0) { $('#question{QID} input:checkbox:lt('+numberToShow+')').each(function(i) { $(this).nextAll('input:hidden').val('Y'); $(this).prop('checked', true).trigger('change'); }); } }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 4 years 2 months ago by tpartner.
The following user(s) said Thank You: Joffm, etc4xx
The topic has been locked.
- etc4xx
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
4 years 2 months ago #193790
by etc4xx
Replied by etc4xx on topic For Multiple Choice Questions, can the sub questions takes x out of y answer
Hi Joffm
Thank you for the explanation.
The sample size is in smaller scale, i.e. 4(x) out of 5(y).
Honestly, i am not good using the javascript, may i know the simpler version of doing this?
Regards
Thank you for the explanation.
The sample size is in smaller scale, i.e. 4(x) out of 5(y).
Honestly, i am not good using the javascript, may i know the simpler version of doing this?
Regards
The topic has been locked.
- etc4xx
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
4 years 2 months ago #193791
by etc4xx
Replied by etc4xx on topic For Multiple Choice Questions, can the sub questions takes x out of y answer
Hi Tony
Thank you for the explanation.
Will try to check on how to use the script as i am not familiar with it.
Regards
Thank you for the explanation.
Will try to check on how to use the script as i am not familiar with it.
Regards
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12937
- Thank you received: 3979
4 years 2 months ago - 4 years 2 months ago #193806
by Joffm
Here it is not necessary to use javascript.
You see, there are only 5 ways to select 4 out of 5.
1,2,3,4
1,2,3,5
1,2,4,5
1,3,4,5
2,3,4,5
So it is sufficient to create a random number between 1 and 5 and set the subquestion relevance accordingly
Subquestion 1: (random!=5)
Subquestion 2: (random!=4)
Subquestion 3: (random!)
Subquestion 4: (random!=2)
Subquestion 5: (random!=1)
Joffm
Just calculate "y over x" and decide what is easier for you.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic For Multiple Choice Questions, can the sub questions takes x out of y answer
Hi, therefore I asked.The sample size is in smaller scale, i.e. 4(x) out of 5(y).
Here it is not necessary to use javascript.
You see, there are only 5 ways to select 4 out of 5.
1,2,3,4
1,2,3,5
1,2,4,5
1,3,4,5
2,3,4,5
So it is sufficient to create a random number between 1 and 5 and set the subquestion relevance accordingly
Subquestion 1: (random!=5)
Subquestion 2: (random!=4)
Subquestion 3: (random!)
Subquestion 4: (random!=2)
Subquestion 5: (random!=1)
Joffm
Just calculate "y over x" and decide what is easier for you.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 2 months ago by Joffm.
The following user(s) said Thank You: etc4xx
The topic has been locked.
- etc4xx
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
4 years 2 months ago #193809
by etc4xx
Replied by etc4xx on topic For Multiple Choice Questions, can the sub questions takes x out of y answer
Hi Joffm
i have been trying with the script. may i know what are the connecting points between the script and the questions? (i.e. to link the choice of subquestions to the question). Can you show which part of the script i should alter? (if it is possible)
If i intend to do a 10 quiz questions, which consist of single choice questions, multiple choice questions, do i:
a) have to have 1 main script and link it to other question (assuming it shares the same set of answer)
b) have several scripts to cater each of the question. (different answers)
I am interested in the script method, but im having almost no knowledge with regards to it.
Secondly, with regards to the simple method, if the choice of answers is consisting non-numerical option (i.e. yellow , green, red, blue & purple)
Thank you for your time and it is much appreciated.
Regards,
i have been trying with the script. may i know what are the connecting points between the script and the questions? (i.e. to link the choice of subquestions to the question). Can you show which part of the script i should alter? (if it is possible)
If i intend to do a 10 quiz questions, which consist of single choice questions, multiple choice questions, do i:
a) have to have 1 main script and link it to other question (assuming it shares the same set of answer)
b) have several scripts to cater each of the question. (different answers)
I am interested in the script method, but im having almost no knowledge with regards to it.
Secondly, with regards to the simple method, if the choice of answers is consisting non-numerical option (i.e. yellow , green, red, blue & purple)
Thank you for your time and it is much appreciated.
Regards,
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12937
- Thank you received: 3979
4 years 2 months ago #193826
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic For Multiple Choice Questions, can the sub questions takes x out of y answer
Hi,
if you talk about the script I provided:
You see there is one line
This is to create an array with total numbers from 1 to 50. If you have less or more, adapt.
There is another line
Here you set the numbers of subquestions you want to show.
Then you get a string in the hidden question Q0 like #,10,49,23,1,32,...
Therefore you may comment "//" the line
to make this question visible.
And in your question there is a subquestion relevance like strpos(Q0,",1,")>0
Meaning: If the string ",1," is in the calculated random string, the subquestion is displayed.
Read about "strpos" in the manual.
if you talk about the script I provided:
You see there is one line
Code:
for (var i = 1; i < 51; i++) {
There is another line
Code:
anumbers = arr.slice(0,10).join(',');
Then you get a string in the hidden question Q0 like #,10,49,23,1,32,...
Therefore you may comment "//" the line
Code:
$('#question{QID}').hide();
And in your question there is a subquestion relevance like strpos(Q0,",1,")>0
Meaning: If the string ",1," is in the calculated random string, the subquestion is displayed.
Read about "strpos" in the manual.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.