Forum Discussion
Using Javascript to catch typing in text box
On the second screen in the attached file, I want to have the user type "Item L2" in the text entry box and have the program immediately jump to the next screen without having to click away from the box. I would also like to have the program give corrective feedback as soon as the user types something other than "Item L2" in the box.
I have the following javascript execute when the screen starts to make the text entry box lose focus each time someone types (which is not working):
Array.from(document.querySelectorAll('.acc-textinput')).forEach(el => {
el.addEventListener('keyup', () => {
el.blur();
el.focus();
})
});
What am I doing wrong?
I have the following javascript execute when the text entry loses focus (which is working correctly):
var player = GetPlayer();
let str = player.GetVar("TextEntry43");
//Create a RegExp object using the constructor
let regex = new RegExp(str);
let text = "Item L2";
// Test if the regex matches the text
let searchGood = regex.test(text);
player.SetVar("Correct_Value", searchGood);
1 Reply
- NancyHyde-35f43Community Member
I got it working! I used a single Javascript that executes when the timeline starts:
const Inputs = () => {
var myInputs = document.querySelectorAll('input[type="text"]');
myInputs.forEach(function(input, index) {
input.addEventListener('keyup', function(event) {
var str = input.value;
var player = GetPlayer();
//Create a RegExp object using the constructor
let regex = new RegExp(str);
let text = "Item L2";
// Test if the regex matches the text
let searchGood = regex.test(text);
player.SetVar("Correct_Value", searchGood);
player.SetVar("TextEntry44", str);
});
});
};
setTimeout(Inputs, 100);Then, I had the remaining triggers set to "when TextEntry44 changes"