Check out the LimeSurvey source code on GitHub!

random order of answer categories, except for...

More
6 years 1 day ago #57451 by ftrifoglio
I found the issue. In the bluengrey template none class is specified for the td containing the answers.
So I just put the ".answer" away from the script and it works.

Please Log in to join the conversation.

More
6 years 1 day ago #57460 by tpartner
All of my workarounds use the default template and may need to be tweaked for other templates.

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
4 years 7 months ago #83650 by Schroder101
Hi There I'm trying to randomise the answers except for the first answer of 8 answers.

I have seen the workaround for keeping the last answer static but I cant even get this to work, possibly the version I am using 1.87, in which case I really should upgrade.

Trying to work out what changes to make to the code to keep the first answer in place? put -7 after ansCount?

"/ Place the last answer created at the end of the list
$( 'input#answer' + sID + 'X' + gID + 'X' + qID + ansCount-7...etc"?

but as cant get the sample to work I am stuck any suggestions?

www.ap.urscorp.com/Consultation/index.php?sid=26127&lang=en

I have attached my question and a Demo survey
Attachments:

Please Log in to join the conversation.

More
4 years 7 months ago #83679 by tpartner
Try this (replacing "QQ" with the question ID):
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Function to allow randomization of all answers except the first one in multiple-options and list-radio questions
		function partRand(qID) { 
 
			// Find the survey and group IDs
			if($( 'input#fieldnames' ).length != 0) {
				var fieldNames = $( 'input#fieldnames' ).attr('value');
				var tmp = fieldNames.split('X');
				var sID = tmp[0];
				var gID = tmp[1];
			}
 
			// Place the first answer created at the beginning of the list
			$('input#answer' + sID + 'X' + gID + 'X' + qID + 1 + '' ).parent().prependTo($( '#question' + qID + ' td.answer ul' ));
 
		}
 
		// Call the function with the question ID
		partRand(QQ);
 
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Schroder101

Please Log in to join the conversation.

More
4 years 7 months ago #83693 by Schroder101
works like a charm, thanks so much!

Please Log in to join the conversation.

More
4 years 7 months ago #83721 by Schroder101
Ok I realized I also need another tweak

in another question with 13 answers i need to keep the first two answers and the last answer static and also retain the 'other' option at the very end.

I edited the code just by adding another couple of lines see attached which sort of worked however I'm not sure how to make 'other' option show up last.

any suggestions?
Attachments:

Please Log in to join the conversation.

More
4 years 7 months ago #83750 by tpartner
Try this to place the "Other" at the end of the list:
$( 'input#answer' + sID + 'X' + gID + 'X' + qID + 'othercbox' ).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.
The following user(s) said Thank You: Schroder101

Please Log in to join the conversation.

More
4 years 7 months ago #83771 by geejay76
All of these tips are proving very helpful - thanks!

I've been unsuccessfully trying to create a randomisation for a list of 10 attributes with option 10 being a "none of the above" option. In addition to these 10 attributes I also want to include an other option.

I am trying to set up the order of the list so that the first 9 attributes are randomised, then the Other option is displayed, then None at the bottom.

At the moment I can get the randomisation working, but I can;t seem to get the None to lock at the bottom.

Any help would be much appreciated.

Please Log in to join the conversation.

More
4 years 7 months ago #83772 by Schroder101
Ok that worked thanks!

Please Log in to join the conversation.

More
4 years 7 months ago #83773 by Schroder101
Just replace this line in the code posted above - replacing the bit were it calls the first answer only and make sure the other option is activated should work

// Place answer no 10 last below 'other'
$('input#answer' + sID + 'X' + gID + 'X' + qID + 10 + '' ).parent().appendTo($( '#question' + qID + ' td.answer ul' ));

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form