Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.2.2+211115
Own server or LimeSurvey hosting: Own Server
Survey theme/template: bootswatch
==================
(Write here your question/remark)
Hello All,
I have a question regarding multiple choice - questions: I have a MC-Question and want to have 1 exclusive answers (e.g. "Don't know") which deactivates all other answers. Also, the question shall at max allow 2 answers from the rest of answers and then deactivate the rest of the answers (like it does when clicking the exclusive answer). The first part I can easily implement by using the native exlcusive-option, but the second part does trouble me. I found a thread (
forums.limesurvey.org/forum/can-i-do-thi...ecting-more-then-max
) with about the same problem, which lead me to this script:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Maximun answers
var maxAnswers = 2;
// Identify this question
var thisQuestion = $('#question{QID}');
function checkMax() {
$('input[type="checkbox"]', thisQuestion).prop('disabled', false);
if($("input:checked", thisQuestion).length >= maxAnswers) {
$('input[type="checkbox"]', thisQuestion).not(':checked').prop('disabled', true);
}
}
// Initial checkbox states
checkMax();
// Listener on the checkboxes
$('input[type="checkbox"]', thisQuestion).on('change', function(e) {
checkMax();
});
// Remove any "disabled" properties before submitting
$('#limesurvey').on('submit', function(e) {
$('input[type="checkbox"]', thisQuestion).prop('disabled', false);
});
});
</script>
The script works fine, as long as I do not set an exlcusive option. As soon as I set the exclusive option it stops working. Any idea on how to adapt this script which allows me to have one answer which deactivates all other answers and otherwise lets the user chose 2 answers before deactivating the rest?
I have attached a LSS-File with a sample survey.
Thanks in advance!
P.S.: I do know that I can set the number of maximal possible answers, but i want to deactivate all other answers in the questions after the user has chosen two + have one answer which is exclusive on its own.