- Posts: 32
- Thank you received: 2
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Issues with the Default values in array questions Workaround
- NielsFro
- Topic Author
- Offline
- Junior Member
Less
More
6 years 6 months ago #159189
by NielsFro
Issues with the Default values in array questions Workaround was created by NielsFro
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
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
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
6 years 6 months ago #159210
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Issues with the Default values in array questions Workaround
This script will render the last column of an array as "default" answer.
Code:
<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
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13643
- Thank you received: 2491
6 years 6 months ago #159238
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 Issues with the Default values in array questions Workaround
Alternative solution : create an equation question type (1st question in 1st group). ANd put
See
manual.limesurvey.org/Expression_Manager..._Assignment_Operator
Code:
{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)}
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.
- NielsFro
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 32
- Thank you received: 2
6 years 6 months ago #159275
by NielsFro
Replied by NielsFro on 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
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
The topic has been locked.