Welcome to the LimeSurvey Community Forum

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

Multiple Choice - 1 exclusive answer and block all after 2 answers

  • boemsel
  • boemsel's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 weeks ago #227711 by boemsel
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. 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 weeks ago - 3 years 2 weeks ago #227713 by Joffm
Don't set the "Max.Answers" in the GUI.
This is set in the script.





Joffm

By the way:
Now there is a setting to move the "Other" option to a desired place.

But I do not know, when it was implemented.
Now your second script to move the "Other" isn't necessary anymore.

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 2 weeks ago by Joffm.

Please Log in to join the conversation.

  • boemsel
  • boemsel's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 2 weeks ago #227715 by boemsel
Ah, of course it was something as simple as that. Thank you Joffm!

The option to move the other-field seems not to be available in the version my institution uses.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose