Forum Discussion
CurtisStanford
4 years agoCommunity Member
Updating Variable While Typing In Text Input Field
Somebody once shared this JS as a solution, which works well for a single text field on the screen. But it only seems to focus on the first text field if there are multiple. Is there a way to have a...
Nedim
6 months agoCommunity Member
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.
ElizabethParent
6 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++
})
- Nedim6 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.
- ElizabethParent6 months agoCommunity Member
thank you, I use anotehr solution, but I will keep this in mind for the next time.
Related Content
- 9 months ago
- 9 months ago
- 9 months ago