Welcome to the LimeSurvey Community Forum

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

Notifying a user if he didn't answer a a non-mandatory question

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 4 months ago #191829 by tpartner
This will work in 2.x versions:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    checkArray('{QID}', 'You did not answer the question. Do you really want to continue?');
 
    function checkArray(qID, msg) {
 
      // Interrupt next/submit function 
      $('#movenextbtn, #movesubmitbtn').on('click', function(){
 
        var failTest = '';
 
        $('#question'+qID+' tr[id^="javatbd"]').each(function(i) {
          if($('input:radio:checked', this).length < 1) {
            failTest = 1;
            $('>', this).css('background-color', '#E74C3C');
          }
          else {
            $('>', this).css('background-color', '');
          }
        });
        if(failTest == 1) {
          if(confirm(msg)) {
            return true;
          }
          else {
            return false;
          }
        }
      });
 
      $('#question'+qID+' input:radio').on('click', function(){
        $(this).closest('tr').find('th, td');.css('background-color', '');
      });
    }
 
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...2-06.lss
File Size:18 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 4 months ago #191830 by tpartner
And, for the record, this will work in 3.x:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    checkArray('{QID}', 'You did not answer the question. Do you really want to continue?');
 
    function checkArray(qID, msg) {
 
      // Interrupt next/submit function 
      $('#ls-button-submit').on('click', function(){
 
        var failTest = '';
 
        $('#question'+qID+' tr[id^="javatbd"]').each(function(i) {
          if($('input:radio:checked', this).length < 1) {
            failTest = 1;
            $(this).addClass('has-error');
          }
          else {
            $(this).removeClass('has-error');
          }
        });
        if(failTest == 1) {
          if(confirm(msg)) {
            return true;
          }
          else {
            return false;
          }
        }
      });
 
      $('#question'+qID+' input:radio').on('click', function(){
        $(this).closest('tr').removeClass('has-error');
      });
    }
 
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...2-06.lss
File Size:21 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
4 years 4 months ago #191832 by kwalker
Thanks so much, Tony! This is very helpful.
The topic has been locked.
More
3 years 11 months ago #199056 by anisij
Dear All,

Kindly, can this be used with other questions types? like list radio?

Best regards,
Anis
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #199117 by tpartner
What LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose