Randomize questions in a group

Plus d'informations
il y a 6 ans 8 mois #84212 par dspaan
COM_KUNENA_MESSAGE_CREATED_NEW
Hi,

I want to randomize the order of questions in a question group.

I used this javascript which i found in the wiki and pasted it in the code format field group desctiption:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		function shuffleQuestions() {
 
			// Create an array to hold question IDs
			var qArray = new Array();
 
			// Find the group ID of the page
			var fieldNames = $( 'input#fieldnames' ).attr('value');
			var tmp = fieldNames.split('X');
			var sID = tmp[0];
			var gID = tmp[1];
 
			// A function to get the value of a cookie by name
			function getCookie ( cookieName ) {
			    var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' );
				if ( results ) {
					return ( unescape ( results[2] ) );
				}
				else {
					return null;
				}
			}
 
			// Get the session name
			var sessionName = getCookie ( 'PHPSESSID' );
 
			// Check to see if the question order has already been shuffled in this session
			var cookieArray = getCookie ( 'sArray' + gID + '_' + sessionName );
 
			// If already shuffled, use that question order
			if ( cookieArray ) {
				//qArray = $.trim(cookieArray);
				qArray = cookieArray.split(',');
			}
			// If not, go ahead and shuffle
			else {
				// Load the IDs of all questions on the page into the array 
				$( 'div[id^="question"]' ).each(function(i) {
					qArray.push($( this ).attr('id'));
				});
 
				// Shuffle the questions 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(qArray);
 
				// Set a cookie with the value of the shuffled array
				var today = new Date();
				today.setTime( today.getTime() );
				var expires = 2 * 1000 * 60 * 60 * 24; // Expire the cookie in 2 days
				var expiresDate = new Date( today.getTime() + (expires) );
				document.cookie = 'sArray' + gID + '_' + sessionName + '=' + qArray + ';expires=' + expiresDate.toGMTString();
			}
 
			// Wrap the questions in a div
			$( 'div[id^="question"]' ).wrapAll( document.createElement('div') );
			$( 'div[id^="question"]:eq(0)' ).parent().attr('id', 'qWrapper');
			$( 'div#qWrapper' ).css({
				'padding':0,
				'margin':0
			});	
 
			// Insert the questions into the wrapper in the shuffled order
			$.each(qArray, function(i, val){
				$( 'div#' + val + '' ).appendTo( $( '#qWrapper' ) );
			});
 
		}
 
		shuffleQuestions();
 
	});
 
</script>

In the global options i have set Filter HTML XSS to 'No'. But when i use the test button to test the survey the questions in that group are NOT randomized.

I'm using Limesurvey Version 1.92+ Build 120801.
What could be causing it not to work?

In this group there is one question that has a condition which is related to another question in the same group. I suppose i should remove that one?

There are also 3 other questions which should only be shown when a condition is met but the are related to answers on questions in previous groups. I suppose that should not be a problem?

Connexion ou Créer un compte pour participer à la conversation.

LimeSurvey Partners
Plus d'informations
il y a 6 ans 8 mois #84214 par holch
COM_KUNENA_MESSAGE_REPLIED_NEW
I am not quite sure if I am getting you right, but Limesurvey has a feature to randomize questions within a group already.

Have a look at "randomization group" (not the same as a question group).

So you can give all those questions, that should be randomized among each other, the same "randomization group name" and then all questions with the same randomization group name will be randomized among each other.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 6 ans 7 mois #85572 par dspaan
COM_KUNENA_MESSAGE_REPLIED_NEW
Thanks Holch. You got me right.

I had to dig a bit in the forum and even the Bugtracker to find out how it worked but it was quite simple. I simply had to got to the question settings and give all questions that needed to be randomized the same groupname in the Randomization Group name field.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 1 semaine #181670 par Mazi
COM_KUNENA_MESSAGE_REPLIED_NEW
Maybe this is helpful to others: We have written a lengthy blog post about randomizing items at Limesurvey and have also outlined how to randomly show a set of questions, see survey-consulting.com/how-to-randomize-i...ow_questions_on_page

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 1 semaine #181696 par jelo
COM_KUNENA_MESSAGE_REPLIED_NEW
Is SEO time?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 1 semaine #181699 par Mazi
COM_KUNENA_MESSAGE_REPLIED_NEW

jelo écrit: Is SEO time?

Well, if I spent quite some time writing such a blog post for helping others, why not linking it at the appropriate topic so others could also find it?

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 1 semaine #181726 par DenisChenu
COM_KUNENA_MESSAGE_REPLIED_NEW

Mazi écrit:

jelo écrit: Is SEO time?

Well, if I spent quite some time writing such a blog post for helping others, why not linking it at the appropriate topic so others could also find it?

Yes, but same post on 6 years and more older topics … :unsure: :(

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 1 semaine #181729 par Mazi
COM_KUNENA_MESSAGE_REPLIED_NEW
Yes, because those show up first when checking the forum for questions about randomization at Limesurvey.
Just because a topic is old it doesn't mean it is not relevant and since some of these old topics still deal with adding additional code for randomization it helps adding a hint that with the new version there are easier to use solutions.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Connexion ou Créer un compte pour participer à la conversation.

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!