Skip to main content
Known Participant
Oct 26, 2021 5:41 PM UTC
Question

textinput

inputNumber is the instance name for the textinput compenent 

why this code is not working?

this.document.getElementById("inputNumber").focus();

 

    This topic is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    Oct 26, 2021 5:55 PM UTC

    Hi.

     

    It should be:

    document.getElementById("inputNumber").focus();

     

    If that still doesn't work it's because the input element isn't ready yet. So you would have to make sure it's ready using a workaround like setTimeout or running a check in a tick event.

    // setTimeout approach
    setTimeout(function()
    {
    	document.getElementById("inputNumber").focus();
    }, 0);
    
    // or
    
    // tick approach
    function onTick()
    {
    	var input = document.getElementById("inputNumber");
    	
    	if (input)
    	{
    		input.focus();
    		createjs.Ticker.removeEventListener("tick", onTick);
    	}
    }
    
    createjs.Ticker.addEventListener("tick", onTick);

     

    I hope this helps.

     

    Regards,

    JC

    Translate
    Yigal0D4BAuthor
    Known Participant
    Nov 3, 2021 1:55 PM UTC

    thank so mach you allways help me wit your idea.

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Nov 3, 2021 4:09 PM UTC

    You're welcome!

     

    I'm glad I can help!

    Translate