# Focus and highlight text input

**URL:** <https://forum.wixstudio.com/t/focus-and-highlight-text-input/5159>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 13, 2023, 11:22am UTC](https://forum.wixstudio.com/t/focus-and-highlight-text-input/5159 "2023-02-13T11:22:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lhoarnold](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/lhoarnold/32/17534_2.png) [@lhoarnold](https://forum.wixstudio.com/u/lhoarnold)\
**Post date:** [February 13, 2023, 11:22am UTC](https://forum.wixstudio.com/t/focus-and-highlight-text-input/5159/1 "2023-02-13T11:22:22Z")

</div>

Hello,

Is it possible to focus and simultaneously highlight the contents of a text input using code?

$w (“#textInput”). focus ();

So that typing will then overwrite whatever was there previously, or the user chan choose to keep it.

Many thanks,

Luke

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [February 13, 2023, 11:32am UTC](https://forum.wixstudio.com/t/focus-and-highlight-text-input/5159/2 "2023-02-13T11:32:13Z")

</div>

How to highlight text inside a TEXT-BOX…

> **[Highlighting specific text | Velo by Wix](https://community.wix.com/velo/forum/coding-with-velo/highlighting-specific-text)**
>
> Hi Everyone, 
> 
> Could someone help me with a code that would enable to highlight specific text in few pages. Lets say in the home page I would like to highlight only "Jeunesse Esch" in the latest results, next fixture, and table boxes. Also, do the...

And here the example…

[https://russian-dima.wixsite.com/meinewebsite/highlight-mark-some-text](https://russian-dima.wixsite.com/meinewebsite/highlight-mark-some-text)

So that typing will then overwrite whatever was there previously, or the user chan choose to keep it.

To overwrite something inside the TEXT, you first will have to get the whole text out of the TEXT-BOX, then replace some parts of the text and put it back into the TEXT-BOX.

---

<div class="post-metadata">

**Author:** ![lhoarnold](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/lhoarnold/32/17534_2.png) [@lhoarnold](https://forum.wixstudio.com/u/lhoarnold)\
**Post date:** [February 13, 2023, 12:06pm UTC](https://forum.wixstudio.com/t/focus-and-highlight-text-input/5159/3 "2023-02-13T12:06:52Z")

</div>

Thanks for this. I think it’s a slightly different problem though. I want the text inside a text input to be highlighted/selected on focus. Is that possible.

Like this: [https://stackoverflow.com/questions/4067469/selecting-all-text-in-html-text-input-when-clicked](https://stackoverflow.com/questions/4067469/selecting-all-text-in-html-text-input-when-clicked)

I’m imagining something like:  
$w (“#textInput”). selectAll ();

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [February 14, 2023, 1:39am UTC](https://forum.wixstudio.com/t/focus-and-highlight-text-input/5159/4 "2023-02-14T01:39:26Z")

</div>

Use the HTML-Component for your purposes…

Implement this example to your generated HTML-Component-CODE…

```javascript
var input = document.getElementById("textBoxId");
input.value = "Cup of tea";
input.setSelectionRange(0, 3); // Highlights "Cup"
input.focus();

```

I don’t think you will be able to use the INPUT-ELEMENT to create your wished functionality (but not sure).

Maybe you can find more info here …

> **[Highlight Text Inside a Textarea](https://codersblock.com/blog/highlight-text-inside-a-textarea/)**
>
> Let’s start with the bad news. You can’t actually highlight text in a textarea. Any markup you would add to do so would simply display as plain text...
