Code Snippet

Home » Code Snippets » JavaScript » Auto Select Textarea Text

Auto Select Textarea Text

<textarea rows="10" cols="50" onclick="this.focus();this.select()" readonly="readonly">
   example text
</textarea>

Subscribe to The Thread

  1. Jack

    So much easier then with jQuery. Just goes to show, a quick search can save you a lot of time, and KB on the finished site. Thanks Chris!

  2. thx a lot!!! its really helpfull, another trick is sucks!!!

  3. Dhaval

    nice one
    for designer its a very easy with help

  4. سازمان غیر دولتی موسسه پروفسور حسابی دارای مجوز رسمی از سازمان ملی جوانان بوده و در محدوده فعالیت ملی و با محوریت علمی و پژوهشی مشغول به کار می باشد.

  5. surf http://www.rapidmaza.com for sending free sms 400 character and for free sms api

  6. thanks… its work! ^^

  7. Great and Works! Thank you.

  8. Stef

    Just what I was looking for… thanks!

    Do you also have the code to make it automatically copy to the clipboard? That would make my life complete lol.

    cheers

    Stef

  9. This doesn’t work in iOS devices. I’ve seen mention of setSelectionRange() working there, but I can’t get that to work in iOS: http://jsfiddle.net/zBa5n/2/

    Does anyone know how to do this?

  10. Works for me. Thanks!

  11. @Stef: I looked for what you asked about as well and found this article: http://brooknovak.wordpress.com/2009/07/28/accessing-the-system-clipboard-with-javascript/

    In the end, I went with instructions to CTRL+C/CTRL+P as accessing the clipboard ended up sounding like a bit of a nightmare. If it’s good enough for YouTube, it’s good enough for me.

  12. This one is on mouseover:

    *textarea cols=”35″ rows=”3″ onmouseover=”this.focus()” onfocus=”this.select()”>
    TEXT HERE
    */textarea>

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~