var bannedWords = ["cat"],
regex = new RegExp('\\\\b' + bannedWords.join("\\\\b|\\\\b") + '\\\\b', 'i');
console.log(regex);
var that = this;
Event.observe(document,'keydown',function(e){
var choiceID = null;
if (e.keyCode ==32) // if space was pressed
{
//var inputs = jQuery(this.getQuestionContainer()).select('input[type="text"]');
// alert(inputs);
jQuery(function () {
jQuery("input").on("change", function () {
var valid = regex.test(this.value);
if (valid)
{
jQuery("body").css("background-color","blue");
choiceID = 1;
var timer = setTimeout(explode, 4000);
}else{
jQuery("body").css("background-color","red");
choiceID = 1;
window.setTimeout(explode, 4000);
//alert("red");
}
//choiceID = 1;
}); //input.on functin
});
} //end of if statement
}); //event.observe
/*Timer expired function*/
var explode = function(){
if (choiceID==1){
alert(" explode2");
jQuery("body").css("background-color","white");
that.setChoiceValue(choiceID,false);
}
};
}); //end of section
Best answer by TomG
View original