A simple but perfect way to auto-select textbox or textarea using Javascript

Posted by: FitR on February 3rd, 2009 (1,323 views | 3 Comments) 462

Auto Select Textbox And Textarea

This tutorial will show how to auto-select textbox or textarea using Javascript. It’s very simple to do.

First create a textbox or textarea in a form.

And then just put this one line code in the textbox or textarea with onclick method. So it should look like below.

Try the example above here.

If you found any better solutions, please let us know!

Now What?

You might be interested in these related posts.

Help us spread the word across!

Sponsored by
About the Author

Fish in the River delivers a fresh inspiration source for designers, developers and marketers but also anyone who wants to be inspired everyday.

Visit FitR's Homepage       Visit FitR on Twitter

Comments 3 Comments

Leave a Comment
Sankha Jyoti
1 year ago (Feb 11, 2009 at 07.16 am)
Hi,

I find a more simple way to auto select a textarea and it's working on both browser(Internet Explorer and Mozilla firefox). There is no need of giving form name or textarea name and make sure that textarea must be readonly. Here is the code

Loren Ipsum dolor sit amet...Loren Ipsum dolor sit amet...Loren Ipsum dolor sit amet...Loren Ipsum dolor sit amet...Loren Ipsum dolor sit amet...Loren Ipsum dolor sit amet...

Thanks

Leave a Comment

Want a Personal Avatar? Visit www.gravatar.com to get your own gravatar, a globally-recognized avatar.
Sankha Jyoti
1 year ago (Feb 11, 2009 at 07.21 am)
Sorry that code is not shwoing properly. Here it once again.

<textarea name=\"\" readonly=\"readonly\" onclick=\"this.focus(); this.select();\">Loren Ipsum dolor sit...Loren Ipsum dolor sit...Loren Ipsum dolor sit...Loren Ipsum dolor sit...Loren Ipsum dolor sit...Loren Ipsum dolor sit...Loren Ipsum dolor sit...Loren Ipsum dolor sit...
</textarea>

Leave a Comment

Want a Personal Avatar? Visit www.gravatar.com to get your own gravatar, a globally-recognized avatar.
1 year ago (Feb 11, 2009 at 07.40 am)
Thanks for your suggestion Sankha! Ye we can make it shorter and it's much simpler.
Here I have created a HTML file for Sankha's suggestion.
Have a look at here.
http://fishintheriver.com/tutorials/simpler-auto-selecting.html

Leave a Comment

Want a Personal Avatar? Visit www.gravatar.com to get your own gravatar, a globally-recognized avatar.

Leave Comment Leave a Comment

Want a Personal Avatar? Visit www.gravatar.com to get your own gravatar, a globally-recognized avatar.
Submit a Comment
No one knows what he can do until he tries.
{ Publilius Syrus }