Auto Select Textarea Text
<textarea rows="10" cols="50" onclick="this.focus();this.select()" readonly="readonly">
example text
</textarea>
<textarea rows="10" cols="50" onclick="this.focus();this.select()" readonly="readonly">
example text
</textarea>
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!
thx a lot!!! its really helpfull, another trick is sucks!!!
nice one
for designer its a very easy with help
WORKS !!!!
surf http://www.rapidmaza.com for sending free sms 400 character and for free sms api
thanks… its work! ^^
Great and Works! Thank you.
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
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?
Works for me. Thanks!
@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.
This one is on mouseover:
*textarea cols=”35″ rows=”3″ onmouseover=”this.focus()” onfocus=”this.select()”>
TEXT HERE
*/textarea>
Much simpler and more correct:
onfocus=”this.select()”
Don’t rely exclusively on the mouse for driving events, use the generic approach because the keyboard drives events too (Some people cycle through fields using the TAB key much faster than using the mouse). XBox controller is relevant to this scenario too.
The code works like a charm! Thanks, I have been looking all over the internet for something like this!
ohh it was helpful
how about auto highlight “pre code” can you give guidance? thanks
What about ajax loaded textareas? They’ll pretty much fail.
It worked for me. thanks
Thanks for this, it helps too!
This only replaces the first instance can you replace all matching words?
sorry wrong thread
Does not work on chrome.
I am trying to add copy to clipboard function to my wordpress site. any suggestion?
Thanks, I am using this I want to change what is showing and one click selectable in my text area, based on a checkbox.
If you look here (http://indiegospel.org/widget), you see a widget page. My widget has a “Get this widget” tag that links to the widget page to make it “viral” or “shareable”. I would like to make that link optional with a checkbox so that the “Get this widget” tag is displayed or not displayed in the text area depending on user choice.
There is a working example here with the checkbox which controls the showing of the “Grab This” code in this Feedburner widget – http://feedburner.google.com/fb/a/headlineanimator/install?target=code&id=2392250btql00tmh66lqp000ms&w=2
I am basically trying to do the same sort of thing they are doing with my widget.
works Great
thanks
and I have one question, how can I add Button to make a copy of the selected Text?
Works fine. Except tabbing. Clicking it becomes editable but when i use the tab key on my keyboard its not highlighted or editable. Any idea how to fix this? thanks