Welcome, Guest
Username: Password: Remember me

TOPIC: Can I use token attributes as default answers to questions?

Can I use token attributes as default answers to questions? 3 years 3 months ago #62050

  • MikeFloyd
  • MikeFloyd's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Can I use token attributes as default answers to questions?
The administrator has disabled public write access.

Re: Can I use token attributes as default answers to questions? 3 years 3 months ago #62094

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4190
  • Thank you received: 787
  • Karma: 359
Yes.

1) Set up your survey to use JavaScript.

2) Add the following script to the source of the question. Replace "QQ" with the questionquestion 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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Can I use token attributes as default answers to questions? 3 years 3 months ago #62126

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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
The administrator has disabled public write access.

Re: Can I use token attributes as default answers to questions? 1 year 10 months ago #87686

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Can I use token attributes as default answers to questions? 1 year 8 months ago #90999

  • Serafim
  • Serafim's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 114
  • Thank you received: 2
  • Karma: 2
Hi there, how do I do that?
The administrator has disabled public write access.

Re: Can I use token attributes as default answers to questions? 1 year 5 months ago #94529

  • ricardo
  • ricardo's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 116
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Re: Can I use token attributes as default answers to questions? 1 year 5 months ago #94534

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4190
  • Thank you received: 787
  • Karma: 359
You shouldn't need that.

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

Capture2_2013-04-03.JPG
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.
The administrator has disabled public write access.
The following user(s) said Thank You: ricardo
Moderators: ITEd
Time to create page: 0.191 seconds
Donation Image