Welcome, Guest
Username: Password: Remember me

TOPIC: Limesurvey Prefilling answers

Limesurvey Prefilling answers 2 years 3 months ago #78040

  • HMN
  • HMN's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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?
The administrator has disabled public write access.

Re: Limesurvey Prefilling answers 2 years 3 months ago #78067

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

Re: Limesurvey Prefilling answers 2 years 3 months ago #78088

  • HMN
  • HMN's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
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.
The administrator has disabled public write access.

Re: Limesurvey Prefilling answers 2 years 3 months ago #78099

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
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.

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: HMN

Re: Limesurvey Prefilling answers 2 years 3 months ago #78102

  • HMN
  • HMN's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
thanks it works,

and if i want do checked the second and third rows of the array?
The administrator has disabled public write access.

Re: Limesurvey Prefilling answers 2 years 3 months ago #78104

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 3 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: HMN

Limesurvey Prefilling answers 1 year 1 month ago #96514

  • boyan
  • boyan's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 49
  • Thank you received: 9
  • Karma: 1
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.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.130 seconds
Donation Image