random order of answer categories, except for...

More
6 years 6 months ago #57451 by ftrifoglio
ftrifoglio replied the topic: random order of answer categories, except for...
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 6 months ago #57460 by tpartner
tpartner replied the topic: random order of answer categories, except for...
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
5 years 2 months ago #83650 by Schroder101
Schroder101 replied the topic: random order of answer categories, except for...
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
5 years 2 months ago #83679 by tpartner
tpartner replied the topic: random order of answer categories, except for...
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
5 years 2 months ago #83693 by Schroder101
Schroder101 replied the topic: random order of answer categories, except for...
works like a charm, thanks so much!

Please Log in to join the conversation.

More
5 years 1 month ago #83721 by Schroder101
Schroder101 replied the topic: random order of answer categories, except for...
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
5 years 1 month ago #83750 by tpartner
tpartner replied the topic: random order of answer categories, except for...
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
5 years 1 month ago #83771 by geejay76
geejay76 replied the topic: random order of answer categories, except for...
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
5 years 1 month ago #83772 by Schroder101
Schroder101 replied the topic: random order of answer categories, except for...
Ok that worked thanks!

Please Log in to join the conversation.

More
5 years 1 month ago #83773 by Schroder101
Schroder101 replied the topic: random order of answer categories, except for...
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.

Start now!

Just create your account and start using Limesurvey today.

Register now