- Posts: 18
- 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() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the disallowed strings and allert text var disallowed = ['refused', 'none of your business', 'nunya']; var alertText = 'You have entered an invalid string!'; // Interrupt the Next/Submit click $('#movenextbtn, #movesubmitbtn').bind('click', function () { var thisInput = $('input.text', thisQuestion); var thisVal = thisInput.val(); thisInput.removeClass('disallowed-string'); // Loop through all disallowed strings $(disallowed).each(function(i) { // If disallowed string found in input value if(new RegExp('\\b'+this+'\\b', 'i').test(thisVal) == true) { thisInput.addClass('disallowed-string'); // Add a class alert(alertText); // Pop up alert return false; // Exit the loop } }); // Abort the Next/Submit if we found a disallowed string if(thisInput.hasClass('disallowed-string')) { return false; } }); }); </script>
input.disallowed-string { background: pink; border: 1px solid red; }
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the disallowed strings and allert text var disallowed = ['refused', 'none of your business', 'nunya']; var alertText = 'You have entered an invalid string!'; var alertText2 = 'You must enter more than 4 characters!'; // Interrupt the Next/Submit click $('#movenextbtn, #movesubmitbtn').bind('click', function () { var thisInput = $('input.text', thisQuestion); var thisVal = thisInput.val(); thisInput.removeClass('disallowed-string'); if($.trim(thisVal).length < 5) { thisInput.addClass('disallowed-string'); // Add a class alert(alertText2); // Pop up alert } else { // Loop through all disallowed strings $(disallowed).each(function(i) { // If disallowed string found in input value if(new RegExp('\\b'+this+'\\b', 'i').test(thisVal) == true) { thisInput.addClass('disallowed-string'); // Add a class alert(alertText); // Pop up alert return false; // Exit the loop } }); } // Abort the Next/Submit if we found a disallowed string if(thisInput.hasClass('disallowed-string')) { return false; } }); }); </script>
<style type="text/css"> body { background-color: #434343; background-image: url('/upload/surveys/362842/images/buildingbkgd.png'); background-repeat: no-repeat; background-attachment: fixed; background-position: right; }</style> <script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the disallowed strings and alert text var disallowed = ['refused', 'none of your business', 'nunya']; var alertText = 'Please enter the name of the company you work for'; // Interrupt the Next/Submit click $('#movenextbtn, #movesubmitbtn').bind('click', function() { var thisInput = $('input.text', thisQuestion); var thisVal = thisInput.val(); thisInput.removeClass('disallowed-string'); // Loop through all disallowed strings $(disallowed).each(function(i) { // If disallowed string found in input value if(new RegExp('\\b'+this+'\\b', 'i').test(thisVal) === true) { thisInput.addClass('disallowed-string'); // Add a class alert(alertText); // Pop up alert return false; // Exit the loop } }); // Abort the Next/Submit if we found a disallowed string if(thisInput.hasClass('disallowed-string')) { return false; } }); }); </script>What is the name of the company where you currently work?