# Give Text Field Focus on Window Load

**URL:** <https://forum.inductiveautomation.com/t/give-text-field-focus-on-window-load/12698>\
**Category:** Ignition\
**Created:** [February 21, 2017, 2:42am UTC](https://forum.inductiveautomation.com/t/give-text-field-focus-on-window-load/12698 "2017-02-21T02:42:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![buck2825](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@buck2825](https://forum.inductiveautomation.com/u/buck2825)\
**Post date:** [February 21, 2017, 2:42am UTC](https://forum.inductiveautomation.com/t/give-text-field-focus-on-window-load/12698/1 "2017-02-21T02:42:06Z")

</div>

so far I have…

on the Event Handlers Script, visionWindow, visionWindowOpened of my window I have  
event.source.getComponent(“rootContainer”).getComponent(“txtTranxferID”).requestFocusInWindow()  
this returns, TypeError: getComponent(): 1st arg can’t be coerced to int

When I place this under a button on the same window.  
event.source.parent.getComponent(“txtTranxferID”).requestFocusInWindow()  
it works as expected. where did I go wrong?

Thanks for the help in advance.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 21, 2017, 1:21pm UTC](https://forum.inductiveautomation.com/t/give-text-field-focus-on-window-load/12698/2 "2017-02-21T13:21:17Z")

</div>

Window objects don’t have named components, so they don’t take strings in their getComponent() methods. What they do have is a rootContainer property. Try this:`event.source.rootContainer.getComponent("txtTranxferID").requestFocusInWindow()`I’m still not sure it’ll work, though – I don’t remember if components are sufficiently initialized at the window open event to successfully claim focus.

---

<div class="post-metadata">

**Author:** ![buck2825](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@buck2825](https://forum.inductiveautomation.com/u/buck2825)\
**Post date:** [February 21, 2017, 2:06pm UTC](https://forum.inductiveautomation.com/t/give-text-field-focus-on-window-load/12698/3 "2017-02-21T14:06:12Z")

</div>

```auto
event.source.rootContainer.getComponent("txtTranxferID").requestFocusInWindow()
```

This does not throw an error but it also does not give my text field focus.

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [February 21, 2017, 7:44pm UTC](https://forum.inductiveautomation.com/t/give-text-field-focus-on-window-load/12698/4 "2017-02-21T19:44:42Z")

</div>

You’ll have to wrap this call in an invokeLater so it gets called once everything else is finished processing:

```auto
system.util.invokeLater(system.gui.getParentWindow(event).getComponentForPath('Root Container.txtTranxferID').requestFocusInWindow)
```
