I have a <input type="text"> and if user clicks inside it I want to make the content (value) of that box selected. How would I do that?
-
The question is quite broad, I assume you know to use javascript, maybe try and ask about the specificsbenni_mac_b– benni_mac_b2012-05-02 12:29:11 +00:00Commented May 2, 2012 at 12:29
-
a hint: w3schools.com/htmldom/dom_using.aspendo.anaconda– endo.anaconda2012-05-02 12:29:24 +00:00Commented May 2, 2012 at 12:29
-
In IE its not working properly.. If you already have some value inside input box or any placeholder it is not working.. Can you tell me what to do ?FrontEnd Expert– FrontEnd Expert2016-04-26 09:33:20 +00:00Commented Apr 26, 2016 at 9:33
Add a comment
|
4 Answers
<input type="text" onclick="select()"/>
3 Comments
FrontEnd Expert
In IE its not working properly.. If you already have some value inside input box or any placeholder it is not working.. Can you tell me what to do ?
joseantgv
And it's possible to unselect it? My idea is
select(); document.execCommand('copy'); unselect();sasha romanov
how to select() if the onClick event is on another element , let's say an <i> tag then how to use select() to copy the value or the placeholder in the <input> tag, PS the 2 elements are in the same <div> tag parent , but the <i> tag , not a child of <input> tag