Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-highlight an input field on focus

I was wondering if there was a way for text inside a input box (pre loaded using value="") to highlight when the user clicks on it?

input type='text' name='url' id='url' value='http://www.a-link.com/' />

EDIT

I need the text to he highlighted so the user can copy it.

like image 486
Jay Avatar asked Jul 27 '11 16:07

Jay


People also ask

How do you highlight input field on focus?

To auto-highlight an input field on focus with JavaScript, we can call select on the element when the focus event is emitted. to add an input with a value filled in. to select the input with document.

How do you highlight text in input?

For selecting the content of an input (with highlight), use: el. select() . For css manual highlight, see @HashemQolami answer.

How do you highlight a field in HTML?

Description. The HTML <mark> tag is used to mark or highlight text that is of special interest or relevance in an HTML document. Browsers traditionally render the text found within the <mark> tag as text with a yellow background color.

How do you know if input field is in focus?

To check if an input field has focus with JavaScript, we can use the document. activeElement property to get the element in focus. to add an input. to check if the input element is focused.


1 Answers

<input type="text" name="textbox" value="Test" onclick="this.select()" /> 
like image 193
tskuzzy Avatar answered Sep 29 '22 14:09

tskuzzy