- Posts: 3
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var q1ID = 11; var q2ID = 22; var msg = 'Please specify in the comment box.'; // Hide the first 2 text inputs of Q1 $('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide(); $('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide(); // Interrupt next/submit function $('#movenextbtn, #movesubmitbtn').click(function(){ // Reset some stuff var failedMandatory = 0; $('#question'+q1ID+' input.text').css({'background':''}); $('#question'+q2ID+' input.text').val(''); // Loop through all check answers in Q1 $('#question'+q1ID+' input.checkbox:checked').each(function(i){ // Define the row var thisRow = $(this).parents('li:eq(0)'); // Check for empty mandatory text inputs if($('input.text:visible', thisRow).length > 0 && $('input.text', thisRow).val() == '') { $('input.text', thisRow).css({'background':'pink'}); failedMandatory = 1; } // Load the multiple-text question if($('input.text:visible', thisRow).length > 0) { $('#question'+q2ID+' input.text:eq('+i+')').val($('input.text', thisRow).val()); } else { $('#question'+q2ID+' input.text:eq('+i+')').val($.trim($(this).parent().text())); } }); // Abort submit if any mandatory text inputs are empty if(failedMandatory == 1) { alert (msg); return false; } else { return true; } }); }); </script>
You're welcometomdelf wrote: Sorry, false alarm... seems to work now!
Many thanks in any case for your prompt response!
Tom
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var q1ID = 68; var msg = 'Please specify in the comment box.'; // Hide the first 3 text inputs of Q1 $('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide(); $('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide(); $('#question'+q1ID+' li[id^="javatbd"]:eq(2) .comment').hide(); // Interrupt next/submit function $('#movenextbtn, #movesubmitbtn').click(function(){ // Reset some stuff var failedMandatory = 0; $('#question'+q1ID+' input.text').css({'background':''});; // Loop through all check answers in Q1 $('#question'+q1ID+' input.checkbox:checked').each(function(i){ // Define the row var thisRow = $(this).parents('li:eq(0)'); // Check for empty mandatory text inputs if($('input.text:visible', thisRow).length > 0 && $('input.text', thisRow).val() == '') { $('input.text', thisRow).css({'background':'pink'}); failedMandatory = 1; } }); // Abort submit if any mandatory text inputs are empty if(failedMandatory == 1) { alert (msg); return false; } else { return true; } }); }); </script>