Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
Hi,
I desperately need your support to write a script for the following matrix:
I need to have a matrix with 3 columns and 14 rows:
The 14 rows contain 14 different criteria (see pictures) (Code: QY001-QY014).
In the first column (Code: QX001) I need a drop-down where the respondents of the survey decide for each criterion, if it should be included or not. I achieved this already.
The second column (Code: QX002) should then be dependent on the first column. If the respondent chose in the first column 'yes, include', then they would need to choose a logic in the second column with a drop-down. The tricky part here is that each row would contain different drop-down choices for each criteria.
For example, if the respondent decides to include criterion 1 (e.g. presence of NGOs), they must select the logic from a drop-down list in this second column. For this criterion, the choice would be between: Areas with a high presence of NGOs, Areas with a moderate presence of NGOs, Areas with a low or no presence of NGOs. For criterion 2, there would be other logics from which respondents would have to choose and so on. Please see pictures attached.
For the third column (Code: QX003) I need a textfield, which would be optional and not be required to be filled out by respondents.
Y-Skala Rows: 14 Criteria (QY001-QY014)
X-Skala Column:
QX001 Dropdown with the same drop-down choice
QX002 Dropdown with individual drop-down selection by row
QX003 Textfield, which is not obligatory to fill out
I hope, this was understandable.
This is the script that I already worked on. Here the drop-down for the first column is already working. And the third column has a text field, however it's still obligatory to be filled out.
I would appreciate your help regarding the second column and making the textfield not obligatory.
<p><script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
var thisQuestion = $('#question{QID}');
// Insert selects
$('.answer-item.answer_cell_QX001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
<option value="">Please select...</option>\
<option value="1">Yes, include</option>\
<option value="2">No, not include</option>\
</select>');
// Listeners
$('.inserted-select', thisQuestion).on('change', function(i) {
if($(this).val() != '') {
$(this).closest('.answer-item').find('input:text').val($('option:selected',
this).val()).trigger('change');
}
else {
$(this).closest('.answer-item').find('input:text').val('').trigger('change');
}
});
// Returning to page
$('.with-select input:text', thisQuestion).each(function(i) {
var thisCell = $(this).closest('.answer-item');
var inputText = $.trim($(this).val());
$('select.inserted-select', thisCell).val(inputText);
});
// Listeners on select elements
$('.inserted-select', thisQuestion).on('change', function(i) {
if($(this).val() != '') {
$(this).closest('.answer-item').find('input:text').val($.trim($('option:selected',
this).text())).trigger('keyup');
}
else {
$(this).closest('.answer-item').find('input:text').val('').trigger('keyup');
}
});
// Returning to page
$('.with-select input:text', thisQuestion).each(function(i) {
var thisCell = $(this).closest('.answer-item');
var inputText = $.trim($(this).val());
var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html()
== inputText; }).val();
$('select.inserted-select', thisCell).val(selectval);
});
// Clean-up styles
$('select.inserted-select', thisQuestion).css({
'max-width': '100%'
});
$('.with-select input:text', thisQuestion).css({
'position': 'absolute',
'left': '-9999em'
});
});
</script>
<style type="text/css">.custom-array table.subquestion-list col {
width: auto !important;
}
.custom-array table.subquestion-list thead .column-0 { width: 25%; }
.custom-array table.subquestion-list thead .column-1 { width: 20%; }
.custom-array table.subquestion-list thead .column-2 { width: 55%; }
</style>
</p>
Thank you in advance for your help!