- Posts: 17
- 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(){ // The variables var minimums = [5, 5, 20, 30]; var maximums = [50, 50, 70, 100]; var errorAlert = 'One or more of the inputs is out of its allowed range. Please re-enter the values'; // Identify this question var thisQuestion = $('#question{QID}'); // Add some attributes to the numeric inputs $('input.text', thisQuestion).each(function(i) { $(this).attr('data-min', minimums[i]); $(this).attr('data-max', maximums[i]); }); // Listeners on the numeric inputs $('input.text', thisQuestion).bind('keyup change', function(event) { if($(this).val() < Number($(this).attr('data-min')) || $(this).val() > Number($(this).attr('data-max'))) { $(this).closest('li.question-item').addClass('max-min-error'); } else { $(this).closest('li.question-item').removeClass('max-min-error'); } }); // Interrupt the Next/Submit function (to test for max/min errors) $('#movenextbtn, #movesubmitbtn').bind('click', function () { if($('li.max-min-error', thisQuestion).length > 0) { alert(errorAlert); return false; } }); }); </script>
.max-min-error input { background: pink; border: 1px solid red; }