Can I use token attributes as default answers to questions?

More
5 years 9 months ago #62050 by MikeFloyd
Can I use token attributes as default answers to questions?

Please Log in to join the conversation.

More
5 years 9 months ago #62094 by tpartner
Yes.

1) Set up your survey to use JavaScript .

2) Add the following script to the source of the question. Replace "QQ" with the question question ID .

If the text input is empty the script loads it with the token value.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
 
		if($('#question'+qID+' input.text').val() == '') {
 
			$('#question'+qID+' input.text').val('{TOKEN:ATTRIBUTE_1}');
		}
 
	});
 
</script>

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 9 months ago #62126 by TMSWhite
tpartner-

This seems like another common request that the equation parser and Issue #5104 might be able to help with.

The way I've done this in the past was to create hidden Equation questions which could set the value of other variables (e.g. set default values for answers).

/tom

Please Log in to join the conversation.

More
4 years 4 months ago #87686 by Mazi
At Limesurvey 2 (and already at 1.92 as well), you can set default answers using the Expression Manager .


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 2 months ago #90999 by Serafim
Hi there, how do I do that?

Please Log in to join the conversation.

More
3 years 11 months ago #94529 by ricardo01
Hello,

I have a multiple short text question. I'd like to prepopulate some of the fields with data from the token list. I have tried this but have not been able to make it work.

This is the script I'm using

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

var qID = 8568SQ001;

if($('#question'+qID+' input.text').val() == '') {

$('#question'+qID+' input.text').val('{TOKEN:ATTRIBUTE_1}');
}

});

</script>

8568 is the question ID and SQ001 is the code for the first option in the multiple short text question. Is it possible to make this work on this type of question?

thanks

Please Log in to join the conversation.

More
3 years 11 months ago #94534 by tpartner
You shouldn't need that.

You should be able to set the default answer in the LS interface:


Cheers,
Tony Partner

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

Please Log in to join the conversation.