Issues with the Default values in array questions Workaround

More
1 month 2 weeks ago #159189 by NielsFro
NielsFro created the topic: Issues with the Default values in array questions Workaround
Hi all,

I am creating a survey in which I predominantly use array questions. As all questions are mandatory, I want to facilitate completing the survey by always checking the last answer option (answer range from 0%, 10%, ... 100%, no answer; no answer is not set by the survey standards, but is an own answer option - hope you know what I mean?)

I have used a dual-array scale previously, in which the assignment of a default answer worked perfectly using the respective workaround. However now, using only a normal array, it does not work anymore, nothing is checked...
I followed these instructions manual.limesurvey.org/Workarounds:_Manip...s_in_array_questions and also tested if javascript is active by the "Alert", which works fine. My LS version is 2.51.0+160829

This is the code that I put into the "Source" of the question (as you can see, my question ID is 1016, at least I suppose that it is as the title says Edit question: WssbgrdeUndNgr (ID:1016) )

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// A function to pre-check a column of an array
function checkedDefault(qID, column) {
var checkedCol = column - 1;
$('#question'+qID+' tr.subquestions-list').each(function(i) {
if ($('input.checkbox:checked', this).length == 0) {
$('input.checkbox:eq('+checkedCol+')', this).prop('checked', true);
$('input.checkbox:eq('+checkedCol+')', this).parent().find('input[type="hidden"]').val(1);
}
});
}
// Call the function with a question ID and column number
checkedDefault(1016, 12);
});

</script>

Looking forward to your replies! Thanks a lot

Please Log in to join the conversation.

More
1 month 2 weeks ago #159210 by tpartner
tpartner replied the topic: Issues with the Default values in array questions Workaround
This script will render the last column of an array as "default" answer.

<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Default answers
		$('tr.answers-list', thisQuestion).each(function(i) {
			if($('input[type="radio"]:checked', this).length == 0) {
				$('input[type="radio"]:last', this).trigger('click')
			}
		});
	});
 
</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: NielsFro

Please Log in to join the conversation.

More
1 month 2 weeks ago #159238 by DenisChenu
DenisChenu replied the topic: Issues with the Default values in array questions Workaround
Alternative solution : create an equation question type (1st question in 1st group). ANd put
{Q1_SQ001=if(empty(Q1_SQ001.NAOK),"NA",Q1_SQ001.NAOK)}
{Q1_SQ002=if(empty(Q1_SQ002.NAOK),"NA",Q1_SQ002.NAOK)}
{Q1_SQ003=if(empty(Q1_SQ003.NAOK),"NA",Q1_SQ003.NAOK)}
See manual.limesurvey.org/Expression_Manager..._Assignment_Operator

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 month 2 weeks ago #159275 by NielsFro
NielsFro replied the topic: Issues with the Default values in array questions Workaround
Dear tpartner, thank you so much for your help! It works just perfectly :) :)

As I have no JavaScrips skills whatsoever, I don't know if the solution you posted here should be added to the workarounds section or if my case is too special to be posted there.

Denis, thanks a lot to you as well!

Best regards
Niels

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!