- Posts: 16
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
tpartner wrote: Have a look at this post where an array type question is used for ranking - www.limesurvey.org/en/forum/can-i-do-thi...king-question#106841 .
<script type="text/javascript" charset="utf-8"> $(document).ready(function () { // Call the mandatory row function with question ID mandatoryRows(QQ); // A function to render all but the last rows of an array mandatory function mandatoryRows(qID) { var warningText = 'Please complete the highlighted rows.'; // Add a mandatory class to all rows except the last one $('div#question'+qID+' table.question tbody[id^="javatbd"]:not(:last) tr').addClass('mandatory'); // Interrupt the submit function $('#movenextbtn, #movesubmitbtn').click(function(){ var fail = ''; // Loop through all mandatory rows and check for answers $('tr.mandatory').each(function(i){ if($('input.radio:checked', this).length < 1) { $('th, td', this).css({ 'background':'pink' }); fail = 1; } else { $('th, td', this).css({ 'background':'' }); } }); if(fail == 1) { alert (warningText); return false; } else { return true; } }); } }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function () { // Call the mandatory row function with question ID mandatoryRows(QQ); // A function to render all but the last rows of an array mandatory function mandatoryRows(qID) { var warningText = 'Please complete the highlighted rows.'; // Add a mandatory class to all rows except the last one $('div#question'+qID+' table.question tr[id^="javatbd"]:not(:last)').addClass('mandatory'); // Interrupt the submit function $('#movenextbtn, #movesubmitbtn').click(function(){ var fail = ''; // Loop through all mandatory rows and check for answers $('tr.mandatory').each(function(i){ if($('input.radio:checked', this).length < 1) { $('th, td', this).css({ 'background':'pink' }); fail = 1; } else { $('th, td', this).css({ 'background':'' }); } }); if(fail == 1) { alert (warningText); return false; } else { return true; } }); } }); </script>
tpartner wrote: Try this:
Code:<script type="text/javascript" charset="utf-8"> $(document).ready(function () { // Call the mandatory row function with question ID mandatoryRows(QQ); // A function to render all but the last rows of an array mandatory function mandatoryRows(qID) { var warningText = 'Please complete the highlighted rows.'; // Add a mandatory class to all rows except the last one $('div#question'+qID+' table.question tr[id^="javatbd"]:not(:last)').addClass('mandatory'); // Interrupt the submit function $('#movenextbtn, #movesubmitbtn').click(function(){ var fail = ''; // Loop through all mandatory rows and check for answers $('tr.mandatory').each(function(i){ if($('input.radio:checked', this).length < 1) { $('th, td', this).css({ 'background':'pink' }); fail = 1; } else { $('th, td', this).css({ 'background':'' }); } }); if(fail == 1) { alert (warningText); return false; } else { return true; } }); } }); </script>