Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: how to fill the answer from the token

how to fill the answer from the token 1 Jahr 5 Tage her #101805

  • luker
  • lukers Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 5 Tage her #101831

  • luker
  • lukers Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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?
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 5 Tage her #101834

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4369
  • Dank erhalten: 828
  • Karma: 381
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 4 Tage her #101844

  • luker
  • lukers Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 4 Tage her #101849

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4369
  • Dank erhalten: 828
  • Karma: 381
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 4 Tage her #101863

  • luker
  • lukers Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 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!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 4 Tage her #101867

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4369
  • Dank erhalten: 828
  • Karma: 381
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.
Letzte Änderung: 1 Jahr 4 Tage her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 4 Tage her #101869

  • luker
  • lukers Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 9
  • Karma: 0
Many thanks for detailed analysis!

I have asked about radio array. Hope you can help on that as well :)
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 4 Tage her #101870

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4369
  • Dank erhalten: 828
  • Karma: 381
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.
Letzte Änderung: 1 Jahr 4 Tage her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

how to fill the answer from the token 1 Jahr 4 Tage her #101871

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4369
  • Dank erhalten: 828
  • Karma: 381
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.154 Sekunden
Donation Image