Welcome to the LimeSurvey Community Forum

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

Unchecking excluded checkboxes

  • BBCMResearch
  • BBCMResearch's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 1 month ago #141400 by BBCMResearch
Unchecking excluded checkboxes was created by BBCMResearch
Hello,

I have several multiple choice questions in a survey that use the exclusive option for a "none of the above" answer.

If someone clicks other answer options before clicking "none of the above," these other selected answers become grayed-out, which normally would be fine. However, I need them to become "un-checked" as well.

Based on the solution tpartner gave here , it appears that I can insert a script to uncheck other boxes if the exclusive option is selected.

However, I don't know enough to code it. I would greatly appreciate it if someone could help me out.

I use Version 2.50+160901

Thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #141447 by tpartner
Replied by tpartner on topic Unchecking excluded checkboxes
Assuming the exclusive item is last, add this to the question source of the multiple choice questions:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Uncheck all excluded items
    $('div.question-item:last input.checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        $('input.checkbox', thisQuestion).not($(this)).each(function(i) {
          $(this).prop('checked', false);
          $(this).nextAll('input:hidden:eq(0)').attr('value', '');
        });
      }
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch
The topic has been locked.
  • BBCMResearch
  • BBCMResearch's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 1 month ago #141463 by BBCMResearch
Replied by BBCMResearch on topic Unchecking excluded checkboxes
Excellent as always.

However, I do have one question where the last two items in the list are both exclusive. Could you adapt the script to work for both items?

Thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #141469 by tpartner
Replied by tpartner on topic Unchecking excluded checkboxes
Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Uncheck all excluded items
    var itemsLength = $('div.question-item', thisQuestion).length;
    $('div.question-item:gt('+(itemsLength-3)+') input.checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        $('input.checkbox', thisQuestion).not($(this)).each(function(i) {
          $(this).prop('checked', false);
          $(this).nextAll('input:hidden:eq(0)').attr('value', '');
        });
      }
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch
The topic has been locked.
  • BBCMResearch
  • BBCMResearch's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 1 month ago #141471 by BBCMResearch
Replied by BBCMResearch on topic Unchecking excluded checkboxes
Thanks!
The topic has been locked.
  • BBCMResearch
  • BBCMResearch's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
7 years 10 months ago #146209 by BBCMResearch
Replied by BBCMResearch on topic Unchecking excluded checkboxes
Tony,

Thanks for your previous help with this. I now need to use this same script, but with an Other option enabled. However, the Other option is not the exclusive one. So you can enter text into the other field, and that remains visible after the exclusive option is checked.

Is it possible to reset the text field for the other option when the exclusive option is checked?

Thanks!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Away
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
7 years 10 months ago #146232 by DenisChenu
Replied by DenisChenu on topic Unchecking excluded checkboxes

BBCMResearch wrote: .....
Is it possible to reset the text field for the other option when the exclusive option is checked?
....

Don't crosspost please ......
www.limesurvey.org/forum/can-i-do-this-w...lusive-option#146231

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #146252 by tpartner
Replied by tpartner on topic Unchecking excluded checkboxes
BBCMResearch, is the exclusive item last?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • BBCMResearch
  • BBCMResearch's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
7 years 10 months ago #146271 by BBCMResearch
Replied by BBCMResearch on topic Unchecking excluded checkboxes
Hi Tony,

Yes, the exclusive item is last, and the other option is just before it.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 10 months ago #146285 by tpartner
Replied by tpartner on topic Unchecking excluded checkboxes
Try this:

Code:
<script type="text/javascript" charset="utf-8">    
 
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Uncheck all excluded items
    $('div.question-item:last input.checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        $('input.checkbox', thisQuestion).not($(this)).each(function(i) {
          $(this).prop('checked', false);
          $(this).nextAll('input:hidden:eq(0)').attr('value', '');
        });
        $('input[type="text"]', thisQuestion).val('');
      }
    });
 
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch
The topic has been locked.
  • BBCMResearch
  • BBCMResearch's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
7 years 10 months ago #146286 by BBCMResearch
Replied by BBCMResearch on topic Unchecking excluded checkboxes
Works like a charm, thanks Tony!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Away
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
7 years 10 months ago - 7 years 10 months ago #146292 by DenisChenu
Replied by DenisChenu on topic Unchecking excluded checkboxes
Hi Tony,

Just something about javascripting answer and EM, think it's better to use
$(this).prop('checked', false).trigger('change');
$('input[type="text"]', thisQuestion).val('').triiger('keyup')

Unsure it work on 2.5X, but i hope it work directly in 3.0 : see github.com/LimeSurvey/LimeSurvey/blob/de...em_javascript.js#L22

If it don't work : it's a bug

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 7 years 10 months ago by DenisChenu.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose