- Posts: 9
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array numbers, yes checkbox in the last column
- granen
- Topic Author
- Offline
- New Member
Less
More
9 years 3 weeks ago #118840
by granen
Array numbers, yes checkbox in the last column was created by granen
Hi,
Is it possible to use checkboxes only in the last column of an array number question type? I need ten columns first where you add numbers and a last one that is a "I don't know" checkbox. The use checkbox option but only for one column.
//Erik
Is it possible to use checkboxes only in the last column of an array number question type? I need ten columns first where you add numbers and a last one that is a "I don't know" checkbox. The use checkbox option but only for one column.
//Erik
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
9 years 3 weeks ago #118869
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 Array numbers, yes checkbox in the last column
Are you using text inputs or drop-downs?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- granen
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
9 years 3 weeks ago #118870
by granen
Replied by granen on topic Array numbers, yes checkbox in the last column
Text inputs!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
9 years 3 weeks ago - 9 years 3 weeks ago #118871
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 Array numbers, yes checkbox in the last column
Okay, then place the following script in the source of the array.
It will:
It will:
- Hide the text inputs in the last column
- Insert checkboxes in those cells
- When a checkbox is checked, all visible text inputs in that row are cleared and the hidden input is given a value of 1
- When a value is entered in a visible text input, the checkbox in that row is unchecked and the hidden input is cleared
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}') // Add some classes to the answer cells $('td.question-item', thisQuestion).addClass('normal-opt'); $('tr.subquestions-list', thisQuestion).each(function(i) { $('.normal-opt:last', this).removeClass('normal-opt').addClass('exlusive-opt') }); // Insert the checkboxes $('.exlusive-opt input[type="text"]', thisQuestion).hide(); $('.exlusive-opt', thisQuestion).append('<input type="checkbox" class="checkbox">'); // A listener on the text inputs $('.normal-opt input[type="text"]', thisQuestion).on('keyup change paste', function() { var thisInput = $(this); var thisRow = $(this).closest('tr.subquestions-list'); setTimeout(function() { if(thisInput.val() != ''){ $('.exlusive-opt input[type=checkbox]', thisRow).prop('checked', false); $('.exlusive-opt input[type=text]', thisRow).val(''); } }, 100); }); // A listener on the checkboxes $('.exlusive-opt input[type="checkbox"]', thisQuestion).change(function(event) { var thisCell = $(this).closest('td.question-item'); var thisRow = $(this).closest('tr.subquestions-list'); if($(this).is(':checked')) { $('input[type=text]', thisCell).val(1); $('.normal-opt input[type=text]', thisRow).val(''); } else { $('input[type=text]', thisCell).val(''); } }); // Initial states $('.exlusive-opt input[type="text"]', thisQuestion).each(function(i) { var thisCell = $(this).closest('td.question-item'); if($(this).val() != '') { $('input[type=checkbox]', thisCell).prop('checked', true); } }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 3 weeks ago by tpartner.
The following user(s) said Thank You: granen
The topic has been locked.
- granen
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
9 years 3 weeks ago #118874
by granen
Replied by granen on topic Array numbers, yes checkbox in the last column
It works like a charm!
A big thank you for that.
A big thank you for that.
The topic has been locked.