- Posts: 256
- Thank you received: 37
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
random selection of desired option..
- first
- Topic Author
- Offline
- Elite Member
Less
More
10 years 1 month ago #104351
by first
Survey Designer and Programmer
random selection of desired option.. was created by first
Hi Everyone,
Q1 and Q2 is a Multiple choice questions with same answer list and 6 answer options. I want auto select those answers options at Q2 that were answered at Q1. This auto-selection should be based on following two logics.
Logics:
At most 3 should be auto selected at Q2
Random selection.
Answers list of Q1 and Q2:
a
b
c
d
e
f
Please help me out.
Q1 and Q2 is a Multiple choice questions with same answer list and 6 answer options. I want auto select those answers options at Q2 that were answered at Q1. This auto-selection should be based on following two logics.
Logics:
At most 3 should be auto selected at Q2
Random selection.
Answers list of Q1 and Q2:
a
b
c
d
e
f
Please help me out.
Survey Designer and Programmer
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
10 years 1 month ago #104361
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 random selection of desired option..
trivender, I see from your signature that you are using group-by-group mode and the questions are in separate groups.
Do you allow respondents to go backwards in this survey? If so, what do you want to happen to Q2 on subsequent visits?
.
Do you allow respondents to go backwards in this survey? If so, what do you want to happen to Q2 on subsequent visits?
.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- first
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 256
- Thank you received: 37
10 years 1 month ago #104363
by first
Survey Designer and Programmer
Replied by first on topic random selection of desired option..
Tony , First lets assume that I wont allow respondent to move back in survey.
I made Q1 randomized and then created a hidden multiple open text question on the same page. I come up with the following script.
<script>
$(document).ready(function(){
$("#movenextbtn").click(function(){
$("input:text").val("")
var inputBoxIndex = 1;
$( "input:checkbox:checked" ).each(function(){
$("input:text").eq(inputBoxIndex).val($(this).attr("id").substring(25));
inputBoxIndex++;
});
//return false;
});
});
</script>
I made Q1 randomized and then created a hidden multiple open text question on the same page. I come up with the following script.
<script>
$(document).ready(function(){
$("#movenextbtn").click(function(){
$("input:text").val("")
var inputBoxIndex = 1;
$( "input:checkbox:checked" ).each(function(){
$("input:text").eq(inputBoxIndex).val($(this).attr("id").substring(25));
inputBoxIndex++;
});
//return false;
});
});
</script>
Survey Designer and Programmer
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
10 years 1 month ago #104364
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 random selection of desired option..
I'm thinking along the same lines - recording an array of the Q1 answers. My approach would be to put in a hidden element in Q2, since that's where we need to access it.
LS version?
.
LS version?
.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
10 years 1 month ago #104365
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 random selection of desired option..
Assuming you are using 2.05...
1) Add a hidden <p> element to the source of Q2 and use Expression Manager to pipe the Q1 results into that element. There may be a better way to do it, but something like this:
2) Add this script to that question source (I think the comments explain it):
.
1) Add a hidden <p> element to the source of Q2 and use Expression Manager to pipe the Q1 results into that element. There may be a better way to do it, but something like this:
Code:
<p class="q1-answers" style="display:none;">{if(Q1_a == "Y", ",a", '')}{if(Q1_b == "Y", ",b", '')}{if(Q1_c == "Y", ",c", '')}{if(Q1_d == "Y", ",d", '')}{if(Q1_e == "Y", ",e", '')}{if(Q1_f == "Y", ",f", '')}</p>
2) Add this script to that question source (I think the comments explain it):
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); var thisQuestionID = '{QID}'; // Create an array of the Q1 answered codes var q1Answers = $('p.q1-answers', thisQuestion).text().replace(/,/, ''); var q1AnswersArr = q1Answers.split(','); // Shuffle the array function shuffle(o){ for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; } shuffle(q1AnswersArr); // Check the first 3 options in the array $(q1AnswersArr).each(function(i) { if(i < 3) { var thisCode = $.trim(this); $('input[type="checkbox"][id$="X'+thisQuestionID+thisCode+'"]', thisQuestion).prop('checked', true); } }); }); </script>
.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.