Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi
  • Page :
  • 1
  • 2

SUJET : how to fill the answer from the token

how to fill the answer from the token il y a 4 mois 4 semaines #101805

  • luker
  • Portrait de luker
  • Hors ligne
  • Fresh Lemon
  • Messages : 9
  • Karma: 0
Hi,

I would like to pre-fill some answers based on the data in tokens i.e.
case1:
if TOKEN:ATTRIBUTE_1 = Y then one of "multiple choice" box should be selected
case2:
if TOKEN:ATTRIBUTE_2 = abc then "short text" should be filled by abc

I have found in manual the chapter "Caution about using Assignment Operator (=)" in Expression Manager part, but there is no syntax here.
So could please you explain how to use it because my some blind test were unsuccessful.

Thanks in advance for help.
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101831

  • luker
  • Portrait de luker
  • Hors ligne
  • Fresh Lemon
  • Messages : 9
  • Karma: 0
After another manual investigation I can answer myself partially for case2.
For text question I can use "defaults" icon and specify that default should be loaded from the token eg. {TOKEN:ATTRIBUTE_5}. It is fine, default is visible and can be edited.

Problem is still with case1 because "multiple choice" (defaults are defined in a different way) or "table" (there is no defaults option).
I have checked "brute-force" way and added to text question {question1_op1=TOKEN:ATTRIBUTE_5} (where TOKEN:ATTRIBUTE_5 is "Y").
But this approach fixed the choice which cannot be changed by the user (btw the selection is not visible but exists) thus such solution is not proper way to solve the problem, I guess.

So, still the question to the experts: how to 'click' the "multiple choice" or "table" question base on the token?
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101834

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
I don't know whether you can get there with Expression Manager but you might try something like this with JavaScript:

<script type="text/javascript" charset="utf-8">	
	var attribute_1 = '{TOKEN:ATTRIBUTE_1}';
 
	$(document).ready(function() { 
 
		// The answer code to be checked
		var checkedCode = 'op1';
 
		if(attribute_1 == 'Y') {
			// Check the option			
			$('#question{QID} .input.checkbox[id$="X{QID}'+checkedCode+'"]').attr('checked', 'checked');
		}
	});
</script>


A few caveats:
- This is untested
- This would also check that option if a respondent returns to the page
- In LimeSurvey 2.05, you will need to change "attr('checked', 'checked')" to "prop('checked', true)"
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.
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101844

  • luker
  • Portrait de luker
  • Hors ligne
  • Fresh Lemon
  • Messages : 9
  • Karma: 0
Thanks, but it seems it does not work.
Q1: should be the space before .input? (#question{QID} .input)

anyway with and without space it does not work.
Q2: how to test and improve it?

Thanks in advance.


PS. basic javascript alert works fine, I'm using version 2.00+ Build 131107
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101849

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
Yes, there should be a space before .input but no dot.

Try this:
<script type="text/javascript" charset="utf-8">	
	var attribute_1 = '{TOKEN:ATTRIBUTE_1}';
 
	$(document).ready(function() { 
 
		// The answer code to be checked
		var checkedCode = 'op1';
 
		if(attribute_1 == 'Y') {
			// Check the option			
			$('#question{QID} input.checkbox[id$="X{QID}'+checkedCode+'"]').attr('checked', 'checked');
		}
	});
</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.
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101863

  • luker
  • Portrait de luker
  • Hors ligne
  • Fresh Lemon
  • Messages : 9
  • Karma: 0
Yes, it works! Field is checked, but...
another question is configured that should be visible when the box is checked, but now, box is checked but corresponding question is still hide... quite strange :)

I have found in my old data that some years ago, I have used syntax such:
document.getElementById('answer111X222X333Op1').click();

it seems such syntax can be also used here - it works as I want. Is there any contraindication to use it?

But what about array question? How to click the answer?
In this case I don't have any related questions thus any way should be fine :)

Thanks for the help!
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101867

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
The problem with .click() is that it will uncheck the option if already checked. Safer to use the checkconditions() function to show your conditional question:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() { 
 
		// The answer code to be checked
		var checkedCode = 'op1';
 
		if(attribute_1 == 'Y') {
			var checkElement = $('#question{QID} input.checkbox[id$="X{QID}'+checkedCode+'"]');
 
			// Check the option			
			$(checkElement).attr('checked', 'checked');
 
			// Fire checkconditions()
			checkconditions($(checkElement).attr('value'), $(checkElement).attr('name'), $(checkElement).attr('type'));
		}
	});
</script>


What type of array? Radio? Checkbox?
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.
Dernière édition: il y a 4 mois 4 semaines par tpartner.
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101869

  • luker
  • Portrait de luker
  • Hors ligne
  • Fresh Lemon
  • Messages : 9
  • Karma: 0
Many thanks for detailed analysis!

I have asked about radio array. Hope you can help on that as well :)
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101870

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
In that case, you should be able to safely use the .click() method:
<script type="text/javascript" charset="utf-8">	
	var attribute_1 = '{TOKEN:ATTRIBUTE_1}';
 
	$(document).ready(function() { 
 
		// The x-axis code of the answer to be clicked
		var xAxisCode = 'A2';
		// The y-axis code of the answer to be clicked
		var yAxisCode = 'SQ003';
 
		if(attribute_1 == 'Y') {
			var clickElement = $('#question{QID} input.radio[id$="X{QID}'+xAxisCode+'-'+yAxisCode+'"]');
 
			// Click the option			
			$(clickElement).click();
		}
	});
</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.
Dernière édition: il y a 4 mois 4 semaines par tpartner.
L'administrateur a désactivé l'accès en écriture pour le public.

how to fill the answer from the token il y a 4 mois 4 semaines #101871

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 3813
  • Remerciements reçus 683
  • Karma: 328
Come to think of it, you can also make sure that this only occurs if the question has not been previously answered:
<script type="text/javascript" charset="utf-8">	
	var attribute_1 = '{TOKEN:ATTRIBUTE_1}';
 
	$(document).ready(function() { 
 
		// The x-axis code of the answer to be clicked
		var xAxisCode = 'A2';
		// The y-axis code of the answer to be clicked
		var yAxisCode = 'SQ003';
 
		if(attribute_1 == 'Y') {
			var clickElement = $('#question{QID} input.radio[id$="X{QID}'+xAxisCode+'-'+yAxisCode+'"]');
			var clickRow = $(clickElement).closest('.answers-list');
 
			if($('input.radio:checked', clickRow).length == 0) {
				// Check the option			
				$(clickElement).click();
			}
		}
	});
</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.
L'administrateur a désactivé l'accès en écriture pour le public.
  • Page :
  • 1
  • 2
Modérateurs: ITEd
Temps de génération de la page : 0.168 secondes
Donation Image