Forum Discussion
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 about characters control max and min?
I need to solve a javaScript issue. I´m traying to follow a programming code but it does not work!
Any help it is gonna be appreciate!
3 Replies
- NedimCommunity 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-dfeCommunity Member
Hi Nedim!
You are so Kind! Thank you! I´m gonna review it!, I'll let you know if that solution worked.
- NedimCommunity Member
No problem, you are welcome!
Related Content
- 3 months ago
- 10 months ago
- 8 months ago