- Posts: 26
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Default option for array by column
- Matiasko
- Topic Author
- Offline
- Junior Member
Less
More
6 years 2 weeks ago #165161
by Matiasko
Default option for array by column was created by Matiasko
Hello
I would like to know how to make first option (Not applicable) in each column prefilled (default). I already know how to do it in standard array (by row) with the code below:
In addition, I would like to have radio button for first column (I) option 'Not applicable' disabled all the time (no default answer for this column).
My version of Lime: 3.3.1, survey attached.
Thank you in advance
P.S.
It would be helpful to have a page with 'Make default option for question type: xxx' with code for all questions that don't support 'Default answer' or to have it implemented inside LimeSurvey
I would like to know how to make first option (Not applicable) in each column prefilled (default). I already know how to do it in standard array (by row) with the code below:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var qID = {QID}; var q = $('#question'+qID); // Default answers $('table.subquestion-list tr.answers-list', q).each(function(i) { if($('input[type="radio"]:checked', this).length == 0) { $('input[type="radio"]:first', this).trigger('click'); } }); }); </script>
My version of Lime: 3.3.1, survey attached.
Thank you in advance
P.S.
It would be helpful to have a page with 'Make default option for question type: xxx' with code for all questions that don't support 'Default answer' or to have it implemented inside LimeSurvey
Attachments:
The following user(s) said Thank You: szylkrecik
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10637
- Thank you received: 3700
6 years 2 weeks ago #165164
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 Default option for array by column
This script should meet both of your requirements:
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Loop through first-row answers $('tr.answers-list:eq(0) input[type="radio"]', thisQuestion).each(function(i) { // Disable the first radio in the first column if(i == 0) { $(this).prop('disabled', true); } // Default answers else { var thisName = $(this).attr('name'); if($('input[type="radio"][name="'+thisName+'"]:checked', thisQuestion).length == 0) { $(this).trigger('click'); } } }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: szylkrecik
The topic has been locked.
- Matiasko
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 26
- Thank you received: 1
6 years 2 weeks ago #165299
by Matiasko
Replied by Matiasko on topic Default option for array by column
As always works great, thank you!
The topic has been locked.