Forum Discussion
Text entry boxes - update value without losing focus
- 4 days ago
There are several solutions in the community for this. Instead of forcing the focus to move, we can tell the browser to 'listen' for any input activity within the text box and manually push that value into your Storyline variable in real-time. By using an EventListener, we update the text entry variable directly without the input field ever losing focus. Check the example below:
const inputField = document.querySelector('.acc-textinput'); inputField.addEventListener('input', function() { let currentVal = inputField.value; setVar("userEntry", currentVal); }); // optional input round border inputField.style.cssText += "border-radius:50px !important; border:1px solid #fff !important;";
There are several solutions in the community for this. Instead of forcing the focus to move, we can tell the browser to 'listen' for any input activity within the text box and manually push that value into your Storyline variable in real-time. By using an EventListener, we update the text entry variable directly without the input field ever losing focus. Check the example below:
const inputField = document.querySelector('.acc-textinput');
inputField.addEventListener('input', function() {
let currentVal = inputField.value;
setVar("userEntry", currentVal);
});
// optional input round border
inputField.style.cssText += "border-radius:50px !important; border:1px solid #fff !important;";
Thank you. This did the trick! :)
- Nedim2 days agoCommunity Member
Great!
Related Content
- 5 months ago