Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: prefill questions based on attribute's in the token table

prefill questions based on attribute's in the token table 2 years 11 months ago #99808

  • duvemyster
  • duvemyster's Avatar
  • Offline
  • Premium Lime
  • Posts: 24
  • Thank you received: 5
  • Karma: 2
Thank you, Mazi.

I haven't figured out yet what I was doing differently yesterday, though this has been working perfectly for me each time today.
The administrator has disabled public write access.
The following user(s) said Thank You: mayeulk

prefill questions based on attribute's in the token table 3 months 3 weeks ago #135512

  • Anana
  • Anana's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
Hi Joost,

Thank you for your input on this question, I am using your code to pre-fill a limewurvey questionnaire using the last version of lime survey, and it works perfectly!!
However, I have an issue pre-filling a single choice question, but uisng a dropdown list instead of a radio list. The code provided on this forum is not working as soon as we select a dropdown format. As I have some long list (e.g countries code) to fill in, it would be very convenient to use a dropdown.
Did you by any chance already encounter the same issue? Or would you have a solution to pre-fill a dropdown? I haven't found any by far.

Thanks in advance and all the best!
The administrator has disabled public write access.

prefill questions based on attribute's in the token table 3 months 3 weeks ago #135519

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5977
  • Thank you received: 368
  • Karma: 260
1. Did the solution work for drop downs at previous Limesurvey versions?

2. Please post a link to a short sample survey.

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.

prefill questions based on attribute's in the token table 3 months 2 weeks ago #135538

  • Anana
  • Anana's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
Thanks for your answer.

1. We never tried it for drop downs at previous versions, we did it here for the first time.

2. For instance, we want to create a drop down list of 4 choices for the respondents, asking them to select the role of their institution (NSO/ Academi/ Private sector, IO). See excel sheet. The code works perfectly for pre-filling a radio list, but does not prefill for dropdown. I am using the code below:

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
if('{TOKEN:ATTRIBUTE_1}' == 'NSO') $("input#answer38934X2077X29244A1").attr('checked', true);
if('{TOKEN:ATTRIBUTE_1}' == 'Academia') $("input#answer38934X2077X29244A2").attr('checked', true);
if('{TOKEN:ATTRIBUTE_1}' == 'Private Sector') $("input#answer38934X2077X29244A3").attr('checked', true);
if('{TOKEN:ATTRIBUTE_1}' == 'IO') $("input#answer38934X2077X29244A4").attr('checked', true);
});
</script>

With A1 to A4 being the corresponding answer options for this question.
Attachments:
The administrator has disabled public write access.

prefill questions based on attribute's in the token table 3 months 2 weeks ago #135546

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6199
  • Thank you received: 1374
  • Karma: 538
You need to do something like this for drop-downs (select elements):

<script type="text/javascript" charset="utf-8">		
 
	$(document).ready(function() {
 
		if('{TOKEN:ATTRIBUTE_1}' == 'NSO' && $('#answer38934X2077X29244').val() == '') {
			$('#answer38934X2077X29244 option').removeAttr('selected');
			$('#answer38934X2077X29244 option[value="A1"]').attr('selected', 'selected'); 
			$('#answer38934X2077X29244').val('A1');
		}
		if('{TOKEN:ATTRIBUTE_1}' == 'Academia' && $('#answer38934X2077X29244').val() == '') {
			$('#answer38934X2077X29244 option').removeAttr('selected');
			$('#answer38934X2077X29244 option[value="A2"]').attr('selected', 'selected'); 
			$('#answer38934X2077X29244').val('A2');
		}
		if('{TOKEN:ATTRIBUTE_1}' == 'Private Sector' && $('#answer38934X2077X29244').val() == '') {
			$('#answer38934X2077X29244 option').removeAttr('selected');
			$('#answer38934X2077X29244 option[value="A3"]').attr('selected', 'selected'); 
			$('#answer38934X2077X29244').val('A3');
		}
		if('{TOKEN:ATTRIBUTE_1}' == 'IO' && $('#answer38934X2077X29244').val() == '') {
			$('#answer38934X2077X29244 option').removeAttr('selected');
			$('#answer38934X2077X29244 option[value="A4"]').attr('selected', 'selected'); 
			$('#answer38934X2077X29244').val('A4');
		}
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

prefill questions based on attribute's in the token table 3 months 2 weeks ago #135548

  • Anana
  • Anana's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
Thank you very much, I'll test it!

Cheers
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.344 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form