Skip to main content
Known Participant
October 26, 2021
Question

textinput

  • October 26, 2021
  • 1 reply
  • 136 views

inputNumber is the instance name for the textinput compenent 

why this code is not working?

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

 

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    October 26, 2021

    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

    Yigal0D4BAuthor
    Known Participant
    November 3, 2021

    thank so mach you allways help me wit your idea.

    JoãoCésar17023019
    Community Expert
    Community Expert
    November 3, 2021

    You're welcome!

     

    I'm glad I can help!