- Posts: 6
- Thank you received: 1
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
- joosts
- Topic Author
- Offline
- New Member
Less
More
13 years 1 month ago #57265
by joosts
prefill questions based on attribute's in the token table was created by joosts
For a survey, I need to complete a few questions based on info in the token table. The idea is to load info from an external database to the token table, than use limesurvey to check if these data are correct.
Based on info here,I got it to work for text input questions, for example below:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("answer74931X156X880").value = '{TOKEN:FIRSTNAME}' }
});
</script>
But I failed in both multiple choice and single choice questions.
I tried like this:
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("answer74931X156X885").value = 'A1' }
and like this
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("answer74931X156X884A1").value = Y }
and even
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("input#answer74931X156X884A1").attr('checked', true)}
Based on info here,I got it to work for text input questions, for example below:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("answer74931X156X880").value = '{TOKEN:FIRSTNAME}' }
});
</script>
But I failed in both multiple choice and single choice questions.
I tried like this:
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("answer74931X156X885").value = 'A1' }
and like this
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("answer74931X156X884A1").value = Y }
and even
if('{TOKEN:ATTRIBUTE_1}' == '1') {
document.getElementById("input#answer74931X156X884A1").attr('checked', true)}
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
13 years 1 month ago #57275
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic prefill questions based on attribute's in the token table
Hello,
You don't have to use document.getElementById with jquery, and here you use jquery and pure javascript, i don't think it can work like that.
Try:
You don't have to use document.getElementById with jquery, and here you use jquery and pure javascript, i don't think it can work like that.
Try:
Code:
if('{TOKEN:ATTRIBUTE_1}' == '1') { ("input#answer74931X156X884A1").attr('checked', true); }
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- joosts
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 1
13 years 1 month ago #57287
by joosts
Replied by joosts on topic prefill questions based on attribute's in the token table
I tried both
and also just to check
and neither of them worked.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if('{TOKEN:ATTRIBUTE_1}' == '1') { ("input#answer74931X156X884A1").attr('checked', true); } }); </script>
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { ("input#answer74931X156X884A1").attr('checked', true); }); </script>
and neither of them worked.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
13 years 1 month ago #57288
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic prefill questions based on attribute's in the token table
Can you post a link to your survey ?
And oups ... the $ ...
And oups ... the $ ...
Code:
$("input#answer74931X156X884A1").attr('checked', true);
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: joosts
The topic has been locked.
- joosts
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 1
13 years 1 month ago #57291
by joosts
Replied by joosts on topic prefill questions based on attribute's in the token table
that dollar did it, for both multiple and single answer option!
merci beaucoup!
merci beaucoup!
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
13 years 1 month ago #57306
by Mazi
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
Replied by Mazi on topic prefill questions based on attribute's in the token table
Joost, to share your knowledge with other users, ca you write a short tutorial how to prefill different question types like text, single choice, multiple choice, ...?
That would be great!
That would be great!
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.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
13 years 1 month ago #57359
by DenisChenu
docs.limesurvey.org/tiki-index.php?page=...nswer_default_value_
update it with jquery
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic prefill questions based on attribute's in the token table
Maybe make correction to this one:Mazi wrote: Joost, to share your knowledge with other users, ca you write a short tutorial how to prefill different question types like text, single choice, multiple choice, ...?
That would be great!
docs.limesurvey.org/tiki-index.php?page=...nswer_default_value_
update it with jquery
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- joosts
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 1
13 years 1 month ago #57366
by joosts
Replied by joosts on topic prefill questions based on attribute's in the token table
I'm still working out some details, but I'll write it out soon. I'm making an xls to make programming easier, should I include that file somehow too?
The topic has been locked.
- joosts
- Topic Author
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 1
13 years 1 month ago #57374
by joosts
Replied by joosts on topic prefill questions based on attribute's in the token table
Still having some trouble. I got everything to work fine for both single and multiple answers. But I have one multi answer question with over 60 answer options. I have it encoded in 12 attributes, each of which can contain one of the 60 answer options.
For example for person Y, attribute_3 may contain 21, which implies answer option X21 on question 884.
The code below does the trick in simple test, though it's not elegant. But when I encode all the attribute fields for all the answer options, Limesurvey freaks and messes with the code. Which is totally rational, given the redundancy of all that code.
I guess it would be better to do it something like this:
But I can't find the proper JQUERY syntax for OR statements. Any hints?
For example for person Y, attribute_3 may contain 21, which implies answer option X21 on question 884.
The code below does the trick in simple test, though it's not elegant. But when I encode all the attribute fields for all the answer options, Limesurvey freaks and messes with the code. Which is totally rational, given the redundancy of all that code.
Code:
if('{TOKEN:ATTRIBUTE_3}' == '21') {$("input#answer74931X156X884X21").attr('checked', true);} if('{TOKEN:ATTRIBUTE_3}' == '22') {$("input#answer74931X156X884X22").attr('checked', true);} if('{TOKEN:ATTRIBUTE_3}' == '23') {$("input#answer74931X156X884X23").attr('checked', true);} if('{TOKEN:ATTRIBUTE_4}' == '21') {$("input#answer74931X156X884X21").attr('checked', true);} if('{TOKEN:ATTRIBUTE_4}' == '22') {$("input#answer74931X156X884X22").attr('checked', true);} if('{TOKEN:ATTRIBUTE_4}' == '23') {$("input#answer74931X156X884X23").attr('checked', true);}
I guess it would be better to do it something like this:
Code:
if('{TOKEN:ATTRIBUTE_3}' == '21' OR '{TOKEN:ATTRIBUTE_4}' == '21' OF '{TOKEN:ATTRIBUTE_5}' == '21' OR ...) {$("input#answer74931X156X884X21").attr('checked', true);}
But I can't find the proper JQUERY syntax for OR statements. Any hints?
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
13 years 1 month ago #57385
by DenisChenu
OR = ||
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic prefill questions based on attribute's in the token table
It's not jquery, but javascript herejoosts wrote: But I can't find the proper JQUERY syntax for OR statements. Any hints?
OR = ||
Code:
if('{TOKEN:ATTRIBUTE_3}' == '21' || '{TOKEN:ATTRIBUTE_4}' == '21' || '{TOKEN:ATTRIBUTE_5}' == '21' ) { $("input#answer74931X156X884X21").attr('checked', true); }
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.