Welcome, Guest
Username: Password: Remember me

TOPIC: random selection of desired option..

random selection of desired option.. 8 months 2 weeks ago #104351

  • trivender
  • trivender's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 146
  • Thank you received: 7
  • Karma: 7
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.
Trivender Singh
Survey Designer and Programmer
"I always suggest to have a group by group display layout and create a seprate group for each question. This will be extra work but you will get flexiblity to create your question by using more than more lime survey question types."
The administrator has disabled public write access.

random selection of desired option.. 8 months 2 weeks ago #104361

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4269
  • Thank you received: 803
  • Karma: 368
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?


.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

random selection of desired option.. 8 months 2 weeks ago #104363

  • trivender
  • trivender's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 146
  • Thank you received: 7
  • Karma: 7
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>
Trivender Singh
Survey Designer and Programmer
"I always suggest to have a group by group display layout and create a seprate group for each question. This will be extra work but you will get flexiblity to create your question by using more than more lime survey question types."
The administrator has disabled public write access.

random selection of desired option.. 8 months 2 weeks ago #104364

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4269
  • Thank you received: 803
  • Karma: 368
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?


.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

random selection of desired option.. 8 months 2 weeks ago #104365

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4269
  • Thank you received: 803
  • Karma: 368
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:
<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):
<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.176 seconds
Donation Image