Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Combine Array with numeric input with exclusive check boxes for column

  • MVelikova
  • MVelikova's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago - 2 years 8 months ago #218395 by MVelikova
Hello, I'm working with Lime Survey ver 2.00 Build 131022. I want to make last row in my array with checkboxes "not applicable". I was able to add them, but not to manipulate. I want if their .attr('checked')==true, to delete all values ​​in the corresponding column, and to put a value of 100 in the hidden input.Can you, please help me?<script>$(document).ready(function(){    $('
Last edit: 2 years 8 months ago by MVelikova.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #218413 by holch
Please, please, please upgrade your installation. Your installation is almost 8 (in words EIGHT) years old. Not only is it the very first release of this branch of Limesurvey (the early releases usually have a higher chance of bugs and security issues, which will be corrected with the later updates), but it is also a deprecated branch which hasn't been supported for many, many years now.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

  • MVelikova
  • MVelikova's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #218427 by MVelikova
Ok, thanks for the advice. I have constantly active surveys and I have been postponing it for a long time

Please Log in to join the conversation.

  • MVelikova
  • MVelikova's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228800 by MVelikova
Hello,Now I'm working with Lime Survey ver 5.2.4+211129 and my old script does not working for array with checkboxes "not applicable". Can you please help me@

<script type="text/javascript" charset="utf-8">


$(document).ready(function(){
$('#question{23} table :last-child >:last-child > td').each(function(){
var textinputid=$(this).find('input:text').attr('id');
$(this).find('input:text').hide();
$(this).append("<input type='checkbox' input id='"+textinputid+"' class='checkbox' name ='"+textinputid.substring(6,30)+"' data-copy='"+textinputid+"' />");
});
document.getElementById("answer478639X5X23SQ002_SQ1").style.display='none';
document.getElementById("answer478639X5X23SQ002_SQ2").style.display='none';
document.getElementById("answer478639X5X23SQ005_SQ1").style.display='none';
document.getElementById("answer478639X5X23SQ005_SQ2").style.display='none';

var qID = {23};
var thisQuestion = $('#question'+qID);

$('input[type="text"]', thisQuestion ).keyup(function(){
if($(this).val() != '') {
$('input.checkbox', thisQuestion ).attr('checked', false);
$('answer478639X5X23SQ009_SQ1').val('');
$('answer478639X5X23SQ009_SQ2').val('');
}
});

$('input.checkbox', thisQuestion).click(function() {
var item= $(this).closest('input[type="checkbox').attr('id');
if(item=='answer478639X5X23SQ009_SQ1') {
$('answer478639X5X23SQ001_SQ1').val('0');
$('answer478639X5X23SQ003_SQ1').val('0');
$('answer478639X5X23SQ004_SQ1').val('0');
$('answer478639X5X23SQ006_SQ1').val('0');
$('answer478639X5X23SQ007_SQ1').val('0');
$('answer478639X5X23SQ008_SQ1').val('0');
$('answer478639X5X23SQ009_SQ1').val('100');

}
if(item=='answer478639X5X23SQ009_SQ2') {
$('answer478639X5X23SQ001_SQ2').val('0');
$('answer478639X5X23SQ003_SQ2').val('0');
$('answer478639X5X23SQ004_SQ2').val('0');
$('answer478639X5X23SQ006_SQ2').val('0');
$('answer478639X5X23SQ007_SQ2').val('0');
$('answer478639X5X23SQ008_SQ2').val('0');
$('answer478639X5X23SQ009_SQ2').val('100');

}

});



});
</script>

Please Log in to join the conversation.

  • MVelikova
  • MVelikova's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228801 by MVelikova
I want to make this question mandatory as we do need this data but I also want a Not Applicable or Cannot answer option for those who really cannot answer the question.
Is there a way I could add a checkbox to the end of each column that, if selected, excludes the number arrays and accepts that as an answer?  

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #228813 by tpartner
I'm not surprised. The HTML structure of survey elements has completely changed since your old version.

Can you attach a small sample survey (.lss file) containing only that question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • MVelikova
  • MVelikova's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago - 1 year 10 months ago #228814 by MVelikova
Now I'm try to modify this script to columns instead of rows
Last edit: 1 year 10 months ago by MVelikova.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #228919 by tpartner
I asked for a survey export (.lss file) containing only that question, not a question export. The volunteers here don't want to waste time creating surveys to help you.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • MVelikova
  • MVelikova's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228922 by MVelikova
I'm sorry, it's my fault. I thought you wanted to export only this array. There is a survey export (.lss file)

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #228924 by tpartner
Yes, I did only want the relevant question. Please provide a survey export (.lss file) containing only that question. I don't have time to go through a Bulgarian survey with 28 questions trying to figure out which is the one that you are modifying.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • MVelikova
  • MVelikova's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #228926 by MVelikova

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #228930 by tpartner
In 5.x, this script and style sheet in the source of an array-numbers-texts question will insert check-boxes in the last row. These check-boxes will be exclusive of all inputs in their columns:


JavaScript:
Code:
<script type="text/javascript" data-author="Tony Partner">  
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
    var exclusiveRow = $('tr[id^="javatbd"]:last', thisQuestion);
    var normalRows = $('tr[id^="javatbd"]', thisQuestion).not(exclusiveRow);
 
    // The value to be loaded in the exclusive inputs
    var exclusiveVal = '1';
 
    // Index the array columns
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
      $('> *', this).each(function(i) {
        $(this).attr('data-index', i);
      });
    });
 
    // Hide the last-row inputs
    $(':text', exclusiveRow).hide();
 
        // Insert the check-boxes
    $('.answer-item', exclusiveRow).each(function(i) {
      var thisIndex = $(this).attr('data-index');
      $(this).addClass('with-inserted-checkbox').append('<span class="checkbox-item">\
          <input type="checkbox" name="insertedInput'+thisIndex+'" id="insertedInput'+thisIndex+'" value="" />\
          <label for="insertedInput'+thisIndex+'" class="checkbox-label control-label"></label>\
        </span>');
    });
 
    // A listener on the normal text inputs
    $('input[type="text"]', normalRows).on('change keyup', function (event) {
      if($.trim($(this).val()) != '') {
        var thisCell = $(this).closest('.answer-item');
        var thisIndex = $(thisCell).attr('data-index');
        $('.answer-item[data-index="'+thisIndex+'"] input[type="hidden"]', exclusiveRow).val('');
        $('.answer-item[data-index="'+thisIndex+'"] :text', exclusiveRow).val('').trigger('keyup');
        $('.answer-item[data-index="'+thisIndex+'"] :checkbox', exclusiveRow).prop('checked', false);
      }
    });
 
    // Listener on the exclusive checkboxes
    $(':checkbox', exclusiveRow).on('change', function (event) {
      if($(this).is(':checked')) {
        var thisCell = $(this).closest('.answer-item');
        var thisIndex = $(thisCell).attr('data-index');
        $('.answer-item[data-index="'+thisIndex+'"] input[type="hidden"]', normalRows).val('');
        $('.answer-item[data-index="'+thisIndex+'"] :text', normalRows).val('').trigger('keyup');
        $(':text', thisCell).val(exclusiveVal).trigger('keyup');
      }
      else {
        $(':text', thisCell).val('').trigger('keyup');
      }
    });
  });
</script>

CSS:
Code:
<style type="text/css" data-author="Tony Partner">
 
  #question{QID} td.with-inserted-checkbox label::before,
  #question{QID} td.with-inserted-checkbox label::after {
    margin-top: -8px;
  }
</style>

Sample survey attached:  

File Attachment:

File Name: limesurvey...7(1).lss
File Size:41 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose