Forum Discussion
Updating Variable While Typing In Text Input Field
Hello JoseTansengco
thank you. I forgot to mention that my script is on a layer. I think this could be the problem.
But I will downgrade my version.
No need to downgrade. Can you upload four slide so I can take a look and send it back to you with a script? Just let me know what you are trying to accomplish.
- ElizabethParent8 months agoCommunity Member
Sorry, I can't. It's for my job and I can't.
But it's for an exercice. The user must enter a postal code in 2 input text (I think it's the first error). I change for the textearea, but, when on a layer, the conde is not working.var monChamp1 = document.querySelector("[data-model-id='5YYnZVYGrR2']") var monInput1 = monChamp1.querySelector('input[type="text"]'); monInput1.addEventListener('input', function(event) { console.log('someone is typing in a box...'); console.log(monInput1.value) /* valeurChamp1 = monChamp1.value; player.SetVar("Saisiedetexte", valeurChamp1);*/ //cpt++ })- Nedim8 months agoCommunity Member
If you have two input fields on the same layer (not the base layer), try using this code (assuming you have two text variables "Saisiedetexte1" and "Saisiedetexte2" ):
const Inputs = () => { var monInputs = document.querySelectorAll('input[type="text"]'); console.log(monInputs); monInputs.forEach(function(input, index) { input.addEventListener('keyup', function(event) { console.log(`someone is typing in box ${index + 1}...`); console.log(input.value); var valeurChamp = input.value; var variableName = "Saisiedetexte" + (index + 1); setVar(variableName, valeurChamp); }); }); }; setTimeout(Inputs, 100);I've also attached the .story file for reference.
- ElizabethParent8 months agoCommunity Member
thank you, I use anotehr solution, but I will keep this in mind for the next time.
Related Content
- 12 months ago
- 12 months ago
- 12 months ago
- 12 months ago