Forum Discussion
TatianaLeon-dfe
3 months agoCommunity Member
Chars control
Hi!
I´m working on a SL activity about Chars max a min control when user typing in Entrytextfield var, but I don´t know why it does not working!!
Please, could you, checking o adding an example ...
Nedim
3 months agoCommunity Member
There are a few syntax errors in your code. Please use the corrected JavaScript below, which includes comments on what has been fixed.
var textFields = document.querySelectorAll('input[type="text"]'); // Use straight quotes
var maxChars = [8, 12];
var player = GetPlayer();
textFields.forEach(function(textField, index) { // fix "funtion" typo and use standard function syntax
textField.addEventListener("input", function() { // fix quotes and typo again
var maxLength = maxChars[index];
if (textField.value.length > maxLength) { // fix "longitud" typo to "length"
textField.value = textField.value.slice(0, maxLength);
player.SetVar("Showlayer", true); // use lowercase player variable and fix quotes
} else {
player.SetVar("Showlayer", false);
}
});
});
If it still doesn’t work, please upload your slide along with a clear explanation of exactly what you are trying to achieve.
TatianaLeon-dfe
3 months agoCommunity Member
Hi Nedim!
You are so Kind! Thank you! I´m gonna review it!, I'll let you know if that solution worked.
- Nedim3 months agoCommunity Member
No problem, you are welcome!
Related Content
- 3 months ago
- 10 months ago
- 8 months ago