Robust Way of Selecting All Text in Textbox

Posted by Emil on Stack Overflow See other posts from Stack Overflow or by Emil
Published on 2010-12-31T05:13:26Z Indexed on 2010/12/31 11:54 UTC
Read the original article Hit count: 138

Filed under:
|
|

I'm trying to have the content of the an HTML textbox be selected fully onFocus.

I know the simple solution of putting a onfocus="this.select()" on the component but this is not a good solution because if a user double clicks into the area the selection is lost and in browsers like chrome it is rarely working like it should and just reverts into input form.

I have searched on Google for a little while and can't find a good solution, most suggestions are of this simple solution.

What I would like it is that the selection inside the textbox not change once selected and if possible the user should not be able to edit the content of the textbox, for example if you have used AdSense when you grab code from AdSense the selection never changes and your unable to alter the code in the textbox.

Any solutions would be appreciated.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html