Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : random selection of desired option..

random selection of desired option.. il y a 7 mois 2 semaines #104351

  • trivender
  • Portrait de trivender
  • Hors ligne
  • Expert Lime
  • Messages : 142
  • Remerciements reçus 6
  • Karma: 6
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."
L'administrateur a désactivé l'accès en écriture pour le public.

random selection of desired option.. il y a 7 mois 2 semaines #104361

  • tpartner
  • Portrait de tpartner
  • En ligne
  • LimeSurvey Team
  • Messages : 4188
  • Remerciements reçus 786
  • Karma: 359
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.
L'administrateur a désactivé l'accès en écriture pour le public.

random selection of desired option.. il y a 7 mois 2 semaines #104363

  • trivender
  • Portrait de trivender
  • Hors ligne
  • Expert Lime
  • Messages : 142
  • Remerciements reçus 6
  • Karma: 6
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."
L'administrateur a désactivé l'accès en écriture pour le public.

random selection of desired option.. il y a 7 mois 2 semaines #104364

  • tpartner
  • Portrait de tpartner
  • En ligne
  • LimeSurvey Team
  • Messages : 4188
  • Remerciements reçus 786
  • Karma: 359
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.
L'administrateur a désactivé l'accès en écriture pour le public.

random selection of desired option.. il y a 7 mois 2 semaines #104365

  • tpartner
  • Portrait de tpartner
  • En ligne
  • LimeSurvey Team
  • Messages : 4188
  • Remerciements reçus 786
  • Karma: 359
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.
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.145 secondes
Donation Image