Code does not work in Chrome or Firefox.. but it works in Safari
Hi,
I have a Limesurvey survey where I'm asking respondents to enter the name of the company where they currently work. I also have a list (from previous versions of this survey), with common junk answers for that question. I want to validate the input against that list. If they enter anything from the list, I want to have a warning pop up.
The folks at the Limesurvey forum gave me some code to try out. Unfortunately this seems to work only on Safari and IE, but not on Chrome or Firefox. I have had other people try answering the question. I have tried different computers, different connections, different platforms to no avail. I have also searched online for some help, but nothing seems to come close to what I'm seeing. Can someone here help me?
Here's the code:
- $(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").on('click', function () {
var thisInput = $('input.text', thisQuestion);
var thisVal = thisInput.val();
thisInput.removeClass('disallowed-string');
// Loop through all disallowed strings
$(disallowed).each(function() {
// 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;
}
});
});
Here's a look at the survey. The issue in question comes up on the 7th question.
http://surveys.elevatedcareers.com/index.php/362842
thanks in advance.
J