Multiple choice question: Uncheck same answer option

Plus d'informations
il y a 1 semaine 3 jours #178914 par KompetenzZ
KompetenzZ a créé le sujet : Multiple choice question: Uncheck same answer option
Hi,

I created two multiple choice questions, and placed the answer options vis-à-vis on the same level with JavaScript. I call these two answer option sets “increase” and “decrease”. They have the same answers. Is it possible to uncheck multiple choice answers across these two questions?
For example, when a certain secondary answer option in “increase” is checked and the respondent checks the same answer in “decrease”, the answer in “increase” should uncheck, vice versa. See picture.
Sorry, the answer options are in German.

Theme and survey is attached.

LS Version 3.14




Fichier attaché :

Nom du fichier : extends1_b...ix21.zip
Taille du ficher :192 ko

Fichier attaché :

Nom du fichier : limesurvey...3785.lss
Taille du ficher :67 ko

Cheers kompetenzz
Pièces jointes :

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

Plus d'informations
il y a 1 semaine 2 jours #178930 par tpartner
tpartner a répondu au sujet : Multiple choice question: Uncheck same answer option
Assuming those are the only multiple choice questions in the group, adding something like this to the source of one question should do the trick:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function() {
 
		$('input:checkbox').on('change', function(i) {
			if($(this).is(':checked')) {
				// Identifyy some stuff...
				var thisQuestion = $(this).closest('.multiple-opt');
				var thisQID = thisQuestion.attr('id').replace(/question/, '');
				var otherQuestion = $('.multiple-opt').not(thisQuestion).first();
				var otherQID = otherQuestion.attr('id').replace(/question/, '');
				var thisCode = $(this).attr('id').split('X'+thisQID)[1];
 
				// Uncheck the check-box in the other question
				$('input:checkbox[id$="X'+otherQID+thisCode+'"]').prop('checked', false).trigger('change');
				$('input:hidden[id^="java"][id$="X'+otherQID+thisCode+'"]').val('');
			}
		});
	});
</script>

Sample survey attached:

Fichier attaché :

Nom du fichier : limesurvey...7851.lss
Taille du ficher :68 ko

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Pièces jointes :

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

Plus d'informations
il y a 1 semaine 1 jour #178961 par KompetenzZ
KompetenzZ a répondu au sujet : Multiple choice question: Uncheck same answer option
Thank you for this javascript and sorry, I was too unprecise in my initial post. I should mention that I applied this workaround from the manual to display secondary answer options: manual.limesurvey.org/Workarounds:_Manip...meSurvey_version_3.x
Therefore the theme with the changes in “custom.css” is attached if necessary.

I would appreciate your help for applying the javascript only for the secondary answer options. I think the secondary answer options in the workaround from the manual are defined with "var secondaryRows", if this would be a help.

Now the answer option unchecks when I initially check a certain secondary option in "Decrease" (second question) and after that the same secondary option in "Increase" (first question). But when I do it in the reversed order, it does not work.

Hopefully the picture makes these considerations a bit clearer.


Cheers kompetenzz
Pièces jointes :

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

Plus d'informations
il y a 1 semaine 1 jour - il y a 1 semaine 1 jour #178966 par KompetenzZ
KompetenzZ a répondu au sujet : Multiple choice question: Uncheck same answer option
Yep, sorry, I saw that you use the class ".multiple-opt" in your javascript and I think I inserted the answers of my second questions without this ".multiple-opt". It the has to do with my javascript to arrage the answer options at the same level and/or theme. I'll take a closer look. Your code is super correct.

As far as I can see it, I just would need to include this "var secondaryRows" in the if condition in order to trigger the javascript only on secondary answers. Could something like that be possible?
...
$('input:checkbox').on('change', function(i) {
        if($(this).is(':checked')) //...&& is/has a variable with the name secondaryRows// {
...

Cheers kompetenzz
Dernière édition: il y a 1 semaine 1 jour par KompetenzZ.

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

Plus d'informations
il y a 4 jours 21 heures #179152 par tpartner
tpartner a répondu au sujet : Multiple choice question: Uncheck same answer option
You have a couple of problems...

1) To identify the secondary rows, in custom.js, change this line:

secondaryRows.css({ 'margin-left':'2.5em' });
To this:
secondaryRows.addClass('secondary-item').css({ 'margin-left':'2.5em' });


2) You have somehow moved both answers lists into the same question so trying to identify items by question ID won't work. Use this as the "un-checking" script:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function() {
 
		// Add classes and attributes
		$('li.question-item').closest('ul').addClass('inserted-question-list');
		$('li.question-item').each(function(i) {
			$(this).attr('data-index', $(this).index());
		});
 
		$('body').on('change', '.secondary-item input:checkbox', function(i) {
			if($(this).is(':checked')) {
				// Identify some stuff...
				var thisQuestion = $(this).closest('.multiple-opt');
				var thisList = $(this).closest('ul.inserted-question-list');
				var otherList = $('.inserted-question-list', thisQuestion).not(thisList).first();
				var thisIndex = $(this).closest('li').attr('data-index');
				var otherItem = $('li[data-index="'+thisIndex+'"]', otherList);
 
				// Uncheck the check-box in the other question
				$('input:checkbox', otherItem).prop('checked', false).trigger('change');
				$('input:hidden', otherItem).val('');
			}
		});
	});
</script>

Sample survey and theme attached:

Fichier attaché :

Nom du fichier : limesurvey...1-12.lss
Taille du ficher :70 ko

Fichier attaché :

Nom du fichier : extends1_b...ix21.zip
Taille du ficher :192 ko

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Pièces jointes :

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

Plus d'informations
il y a 4 jours 16 heures - il y a 4 jours 16 heures #179156 par KompetenzZ
KompetenzZ a répondu au sujet : Multiple choice question: Uncheck same answer option
Wow, this is breathtaking. Thank you for your active participation and inputs in such a fruitful way. I appreciate that.

Yes, I moved both answers lists into the same question because that was the only idea I had for a correct display on smartphones. If the screen width is too small, the second answer list moves below the first one. I guess there are more elegant ways to achieve this :)

Again, this was a great help.


Just for documentation: if someone ever needs these questions with two column answer lists of secondary answer option questions or multiple numeric input questions: Some examples (see screenshot) are attached in the lss file (this lss file only works with the theme attached by tpartner in the post before this one). Sorry, the answer options are in german, but the logic should be understandable.



Fichier attaché :

Nom du fichier : limesurvey...4719.lss
Taille du ficher :118 ko

Cheers kompetenzz
Pièces jointes :
Dernière édition: il y a 4 jours 16 heures par KompetenzZ.

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!