Forum Discussion

AprilDrennan-f8's avatar
AprilDrennan-f8
Community Member
9 months ago

go to new layer when text has been entered in text box

Hi. I have a text box where the user is supposed to enter the number 68, and then I want that specific number to trigger the opening of a new layer without having to enter any other key such as ENTER. The number itself should trigger the layer. Is this possible? I'm assuming I would need some JavaScript maybe? Thank you.

  • Nedim's avatar
    Nedim
    Community Member

    I think you could use a bit help of Javascript. Something like this:

    const textFields = document.querySelectorAll('.acc-textinput');

    textFields.forEach((textField) => {
        textField.addEventListener('keyup', () => {
            textField.blur();
        });
    });

    Put this code in 'Execute Javascript when the timeline starts on this slide' trigger. 
    The blur() method will remove keyboard focus from the current element. Create a trigger in SL to say: Show layer 'correct' when 'NumericEntry' changes if 'NumericEntry' = value 68. As soon as you type 68 into the input field another layer will show up. 

    • AprilDrennan-f8's avatar
      AprilDrennan-f8
      Community Member

      I'm having trouble opening this file for some reason. It could be something on my end I suppose. I will keep trying. Thanks for responding!

      • PhilMayor's avatar
        PhilMayor
        Super Hero

        It uses the similar code that Nedim posted, I just had this lying around from something else.

        Sent from my iPhone