$w("#input1").focus() doesn't seem to set the focus


Only one element on the page–$w(“#input1”) is a textbox input. There is only one javascript command in the “onReady” function which is $w(“#input1”).focus(). But it doesn’t seem to actually set the focus except briefly when the screen first loads–but then when it adjusts the display size to fit the screen, the focus seems to disappear.

editor link here:

Am I missing something here?

Thanks,
Brian Roberts

I also noticed this problem a long time ago. So to solve that, I use a delay when changing focus upon loading.

setTimeout(() => {$w('#input1').focus()}, 1000) //Second delay.

Thanks, Bruno–great tip! I noticed it seems to be a problem more in preview mode than in published mode so maybe it’s related to process overhead induced by the editor.