- Posts: 10104
- Thank you received: 3593
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
- Offline
- LimeSurvey Community Team
Less
More
4 years 4 months ago #191829
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Notifying a user if he didn't answer a a non-mandatory question
This will work in 2.x versions:
Sample survey attached:
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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
4 years 4 months ago #191830
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Notifying a user if he didn't answer a a non-mandatory question
And, for the record, this will work in 3.x:
Sample survey attached:
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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- kwalker
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
4 years 4 months ago #191832
by kwalker
Replied by kwalker on topic Notifying a user if he didn't answer a a non-mandatory question
Thanks so much, Tony! This is very helpful.
The topic has been locked.
- anisij
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 1
3 years 11 months ago #199056
by anisij
Replied by anisij on topic Notifying a user if he didn't answer a a non-mandatory question
Dear All,
Kindly, can this be used with other questions types? like list radio?
Best regards,
Anis
Kindly, can this be used with other questions types? like list radio?
Best regards,
Anis
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
3 years 11 months ago #199117
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Notifying a user if he didn't answer a a non-mandatory question
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.