Any JavaScript Experts Out There?
I found this sample code on the web, but it's not working for me. I'm trying to limit the number of characters a user can enter (for example 5), and if they exceed then I show a layer with an error msg. Here is the code and my SL file. I'm sure it's something simple.
var textFields = document.querySelectorAll(‘input[type=”text”]’);
var maxChars = [8, 12];
var player = GetPlayer();
textFields.forEach(function(textField, index) {
textField.addEventListener(“input”, function() {
var maxLength = maxChars[index];
if (textField.value.length > maxLength) {
textField.value = textField.value.slice(0, maxLength);
player.SetVar(“ShowLayer”, true);
} else {
player.SetVar(“ShowLayer”, false);
}
});
});