# Set Focus to an DOM Input Field

**URL:** <https://discourse.processing.org/t/set-focus-to-an-dom-input-field/17140>\
**Category:** Coding Questions\
**Created:** [January 17, 2020, 2:21pm UTC](https://discourse.processing.org/t/set-focus-to-an-dom-input-field/17140 "2020-01-17T14:21:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olafval](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/olafval/32/7837_2.png) [@olafval](https://discourse.processing.org/u/olafval)\
**Post date:** [January 17, 2020, 2:21pm UTC](https://discourse.processing.org/t/set-focus-to-an-dom-input-field/17140/1 "2020-01-17T14:21:55Z")

</div>

How is it possible to select an input field directly by code, so that you can start typing right away?

I have tried the following commands without success:

input.focus();  
input.style(‘focus’, true);  
input.style(‘focus’, ‘true’);  
input.style(‘focus()’, ‘true’);  
…

[https://p5js.org/examples/dom-input-and-button.html](https://p5js.org/examples/dom-input-and-button.html)

I would be very happy about a clue!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 17, 2020, 6:00pm UTC](https://discourse.processing.org/t/set-focus-to-an-dom-input-field/17140/2 "2020-01-17T18:00:59Z")

</div>

- [Forum.Processing.org/two/discussion/23436/autofocus-for-an-input-element#Item\_1](http://Forum.Processing.org/two/discussion/23436/autofocus-for-an-input-element#Item_1)

---

<div class="post-metadata">

**Author:** ![olafval](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/olafval/32/7837_2.png) [@olafval](https://discourse.processing.org/u/olafval)\
**Post date:** [January 21, 2020, 10:01am UTC](https://discourse.processing.org/t/set-focus-to-an-dom-input-field/17140/3 "2020-01-21T10:01:23Z")

</div>

Thanks a lot. And Yes it is a pity that “autofocus()” is pretty much useless when it’s set inside p5.js.
