Limesurvey Prefilling answers

More
5 years 2 months ago #78040 by HMN
HMN created the topic: Limesurvey Prefilling answers
Hello,

I need help, i have an array question like this:
YES NO NA
option 1
option 2
option 3
option 4

What i want is to prefill some answer, for example:

option 1 automatically have NA answer choosen, is it possible? How?

Please Log in to join the conversation.

More
5 years 2 months ago #78067 by Mazi
Mazi replied the topic: Limesurvey Prefilling answers
It depends on the Limesurvey version you are using. At Limesurvey 1.92 some more questions support default answers.

The alternative solution is to use Javascript to pre-check answers. There should be several examples at the forums.


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
5 years 2 months ago #78088 by HMN
HMN replied the topic: Limesurvey Prefilling answers
im using version 1.91+.
the problem is that i don't understand how to use javascript to prefill the answers.
i try this but doesnt do nothing:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#answer19716X147X177811').attr('checked', true);
});
survey ID: 19716
group ID: 147
question ID: 1778
i want that subquestion 1 have the answer 1 checked.

Please Log in to join the conversation.

More
5 years 2 months ago #78099 by tpartner
tpartner replied the topic: Limesurvey Prefilling answers
1) Set up your survey to use JavaScript .

2) Add the following script to the source of the array. Replace "QQ" with the array question ID (1778 in the example above).

The script looks for checked radios in the first row of the array and, if none found, checks the last one.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var qID = QQ;
 
		if($('#question'+qID+' table.question tbody:first input.radio:checked').length == 0) {
			$('#question'+qID+' table.question tbody:first input.radio:last').attr('checked', true); 
		}				
	});
 
</script>

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

Please Log in to join the conversation.

More
5 years 2 months ago #78102 by HMN
HMN replied the topic: Limesurvey Prefilling answers
thanks it works,

and if i want do checked the second and third rows of the array?

Please Log in to join the conversation.

More
5 years 2 months ago - 5 years 2 months ago #78104 by tpartner
tpartner replied the topic: Limesurvey Prefilling answers
This will check the last option in the first three rows:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var qID = QQ;
 
		$('#question'+qID+' table.question tbody').each(function(i){
			if(i < 3) {
				if($('input.radio:checked', this).length == 0) {
					$('input.radio:last', this).attr('checked', true); 
				}	
			}
		});			
	});
 
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 2 months ago by tpartner.
The following user(s) said Thank You: HMN

Please Log in to join the conversation.

More
4 years 4 weeks ago #96514 by byan
byan replied the topic: Limesurvey Prefilling answers
An easier solution is to use the survey URL. First, find the sid, qid and gid of the question as well as the answer option you are trying to prefill. For example,

sid=94757
gid=28
qid=660
answer option=A2

use the following URL

survey.xxx.org/index.php?sid=94757&94757X28X660=A2

BTW, sid is survey id, gid is groupid, qid is question id.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now