Welcome, Guest
Username: Password: Remember me

TOPIC: Pseudo randomization not working...

Pseudo randomization not working... 3 years 6 days ago #65678

  • vadindot
  • vadindot's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 51
  • Thank you received: 1
  • Karma: 0
I have a lot of questions that all use the same response list, with don't know being anchored to the end. I am using the following script:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Function to allow randomization of all answers except the last one in Multiple options and List/radio questions
		function partRand(sID, gID, qID) { 
 
 
			// Find the number of answers
			var ansCount = ''
                        var otherCNT = ''
			$( 'div#question' + qID + ' td.answer li' ).each(function(i) {
				ansCount = (i + 1);
			});
 
			// Place the last answer created at the end of the list
			$( 'input#answer' + sID + 'X' + gID + 'X' + qID + ansCount + '' ).parent().appendTo($( '#question' + qID + ' td.answer ul' ));
 
		}
 
		// Call the function with the SID, GID and QID
		partRand(81567, 1305, 4698);
 
	});
 
</script>

It is working correctly on the FIRST question, but none of the others.


(Alsom is there a way to anchor the last 2 items?)
The administrator has disabled public write access.

Re: Pseudo randomization not working... 3 years 6 days ago #65684

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4193
  • Thank you received: 789
  • Karma: 359
It is working correctly on the FIRST question, but none of the others.
Have you called the function several times? Something like:
		// Call the function with the SID, GID and QID
		partRand(81567, 1305, 4698);
		partRand(81567, 1305, 4699);
		partRand(81567, 1305, 4700);
		partRand(81567, 1305, 4701);
Alsom is there a way to anchor the last 2 items?
Try replacing this:
			// Place the last answer created at the end of the list
			$( 'input#answer' + sID + 'X' + gID + 'X' + qID + ansCount + '' ).parent().appendTo($( '#question' + qID + ' td.answer ul' ));

With:
			// Place the last answer created at the end of the list
			$( 'input#answer' + sID + 'X' + gID + 'X' + qID + ansCount-1 + '' ).parent().appendTo($( '#question' + qID + ' td.answer ul' ));
			$( 'input#answer' + sID + 'X' + gID + 'X' + qID + ansCount + '' ).parent().appendTo($( '#question' + qID + ' td.answer ul' ));
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.

Re: Pseudo randomization not working... 3 years 6 days ago #65690

  • vadindot
  • vadindot's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 51
  • Thank you received: 1
  • Karma: 0
after double checking a few things i realize that actually it was not working on one question, that question was checkboxes with an exclusive option

each question is in a different group, survey goes group to group

I had found that I had not set the following when I upgraded to 1.91 (shame on me):
$shownoanswer = 0;
$filterxsshtml = false;

now they are set, but it is still not working
The administrator has disabled public write access.

Re: Pseudo randomization not working... 3 years 1 day ago #65855

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
1. Did you adjust the question ID when copying the code to other questions?

2. Do you use the exact same question types?

3. Are those questions within the same group?

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Pseudo randomization not working... 3 years 1 day ago #65865

  • vadindot
  • vadindot's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 51
  • Thank you received: 1
  • Karma: 0
1. Yes I did adjust the QID when copying the code
2. One question is List-Radio, the rest are Multiple/Checkboxes
3. They are all in separate groups
The administrator has disabled public write access.

Re: Pseudo randomization not working... 3 years 1 day ago #65871

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4193
  • Thank you received: 789
  • Karma: 359
vadindot, can you activate a sample survey for us to see?
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.

Re: Pseudo randomization not working... 3 years 1 day ago #65872

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
The code for multiple choice questions would be different because they use different HTML elements which won't be triggered ciorrectly when using the single choice JS code.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Pseudo randomization not working... 3 years 1 day ago #65877

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4193
  • Thank you received: 789
  • Karma: 359
They workaround should work for both single choice (list-radio) and multiple choice (list-checkbox). It moves the <li> elements which exist in both question types.

It is set up for the default template though. What template are you using?
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.

Re: Pseudo randomization not working... 3 years 1 day ago #65882

  • vadindot
  • vadindot's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 51
  • Thank you received: 1
  • Karma: 0
I am using bluengray
The administrator has disabled public write access.

Re: Pseudo randomization not working... 3 years 1 day ago #65887

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4193
  • Thank you received: 789
  • Karma: 359
Try:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Function to allow randomization of all answers except the last one in Multiple options and List/radio questions
		function partRand(sID, gID, qID) { 
 
 
			// Find the number of answers
			var ansCount = ''
			$( 'div#question' + qID + ' div.answers li' ).each(function(i) {
				ansCount = (i + 1);
			});
 
			// Place the last answer created at the end of the list
			$( 'input#answer' + sID + 'X' + gID + 'X' + qID + ansCount + '' ).parent().appendTo($( '#question' + qID + ' div.answers ul' ));
 
		}
 
		// Call the function with the SID, GID and QID
		partRand(81567, 1305, 4698);
 
	});
 
</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.182 seconds
Donation Image