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

More
11 years 6 months ago #118840 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
The topic has been locked.
More
11 years 6 months ago #118869 by tpartner
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.
More
11 years 6 months ago #118870 by granen
Text inputs!
The topic has been locked.
More
11 years 6 months ago - 11 years 6 months ago #118871 by tpartner
Okay, then place the following script in the source of the array.

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: 11 years 6 months ago by tpartner.
The following user(s) said Thank You: granen
The topic has been locked.
More
11 years 6 months ago #118874 by granen
It works like a charm!

A big thank you for that.
The topic has been locked.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose