Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

prefill questions based on attribute's in the token table

  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
10 years 6 months ago - 10 years 6 months ago #99793 by Mazi
duvemyster, I am not quite sure what you are up to, but maybe this helps:
Pre-filling a text field at Limesurvey 1.92 using default answers and Expression Manager

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Last edit: 10 years 6 months ago by Mazi.
The topic has been locked.
More
10 years 6 months ago #99798 by duvemyster
I was trying to pull the default answer in from the token table on a multiple short-text question in 2.00+ .

Should entering {TOKEN:ATTRIBUTE_1} in a default field of a multiple short-text question be working?
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
10 years 6 months ago #99806 by Mazi

duvemyster wrote: Should entering {TOKEN:ATTRIBUTE_1} in a default field of a multiple short-text question be working?

Just give it a try...

...the answer is "yes".

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
More
10 years 6 months ago #99808 by duvemyster
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 following user(s) said Thank You: mayeulk01
The topic has been locked.
More
7 years 10 months ago #135512 by Anana
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 topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
7 years 10 months ago #135519 by Mazi
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
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
More
7 years 10 months ago #135538 by Anana
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #135546 by tpartner
You need to do something like this for drop-downs (select elements):

Code:
<script type="text/javascript" charset="utf-8">    
 
  $(document).ready(function() {
 
    if('{TOKEN:ATTRIBUTE_1}' == 'NSO' &amp;&amp; $('#answer38934X2077X29244').val() == '') {
      $('#answer38934X2077X29244 option').removeAttr('selected');
      $('#answer38934X2077X29244 option[value="A1"]').attr('selected', 'selected'); 
      $('#answer38934X2077X29244').val('A1');
    }
    if('{TOKEN:ATTRIBUTE_1}' == 'Academia' &amp;&amp; $('#answer38934X2077X29244').val() == '') {
      $('#answer38934X2077X29244 option').removeAttr('selected');
      $('#answer38934X2077X29244 option[value="A2"]').attr('selected', 'selected'); 
      $('#answer38934X2077X29244').val('A2');
    }
    if('{TOKEN:ATTRIBUTE_1}' == 'Private Sector' &amp;&amp; $('#answer38934X2077X29244').val() == '') {
      $('#answer38934X2077X29244 option').removeAttr('selected');
      $('#answer38934X2077X29244 option[value="A3"]').attr('selected', 'selected'); 
      $('#answer38934X2077X29244').val('A3');
    }
    if('{TOKEN:ATTRIBUTE_1}' == 'IO' &amp;&amp; $('#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 topic has been locked.
More
7 years 10 months ago #135548 by Anana
Thank you very much, I'll test it!

Cheers
The topic has been locked.
More
6 years 1 month ago #163502 by akankashasharma91
Replied by akankashasharma91 on topic prefill questions based on attribute's in the token table
Hi
I require an urgent help in case of an anonymous survey i want a token field value to be stored in a question which will be of equation type. But i am not able to do it using the above mentioned solution.
Please help.
Thanks in advance.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #163515 by tpartner
This thread has nothing to do with equation type questions. To prefill that question type, you would simply place something like this in the question text - {TOKEN:ATTRIBUTE_1}.

Having said that, if your survey is anonymous, there is no connection to the token table so you cannot access token attributes from within the survey.

manual.limesurvey.org/Participant_settings

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose