Forum Discussion

TatianaLeon-dfe's avatar
TatianaLeon-dfe
Community Member
3 months ago

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

  • Nedim's avatar
    Nedim
    Community 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's avatar
      TatianaLeon-dfe
      Community Member

      Hi Nedim!

      You are so Kind! Thank you! I´m gonna review it!, I'll let you know if that solution worked.

      • Nedim's avatar
        Nedim
        Community Member

        No problem, you are welcome!