Onclick Select All and Copy to Clipboard (javascript)
- 18 Comment
![]()
In sometimes, in html , if you want to select the text for a textbox or a textarea , you can use the following script
function select_all(obj)
{ var text_val=eval(obj);
text_val.focus();
text_val.select();
if (!document.all) return; // IE only
r= text_val.createTextRange();
r.execCommand(\\'copy\\');
} <script type=”text/javascript”>
function select_all(obj)
{ var text_val=eval(obj);
text_val.focus();
text_val.select();
if (!document.all) return; // IE only
r= text_val.createTextRange();
r.execCommand(\\’copy\\’);
} </script>
The html part is:
<input value=”http://www.sajithmr.com” onclick=”select_all(this)” name=”url” type=”text” />The above script will select all the text for input field and copy to clipboard (for IE only)
18 Comments on this post
Trackbacks
-
Brad said:
Well this is just terrible. Just use this simple bit of code in the textbox or textarea.
onFocus=”this.select();”
Or maybe I’m just misinterpreting what your trying to do.
April 19th, 2008 at 12:34 am -
Sajith M.R said:
Brad,
Here not only just select, also copy the content into your clipboard.(Similar to right click select all and copy)
April 19th, 2008 at 12:48 am -
tonk said:
goosebumps
April 19th, 2008 at 12:41 pm -
Derive Host said:
Great Post.
Best Regards
Team
Web Hosting Sri LankaMay 5th, 2008 at 10:53 am -
Pigeon said:
It doesn’t work, at least not in Opera, the line
r.execCommand(\’copy\’);
gives an inline script compilation error at the escaped quotes. If I unescape the quotes it gives a type mismatch error on the same line.
May 6th, 2008 at 12:12 am -
topigeon said:
What part of “The html part is:
The above script will select all the text for input field and copy to clipboard (for IE only)” do you not understand? IE = Internet Explorer != Opera.
June 2nd, 2008 at 5:07 pm -
selva said:
how to copy a text in textbox to clipboard in mozilla???
July 18th, 2008 at 4:24 pm -
Lindsay-Lohan said:
thanks! very nice!
July 31st, 2008 at 8:54 pm -
Anna8 said:
Yes, great job.
Interesting indeed.August 4th, 2008 at 10:54 pm -
Raja said:
Check this link… working good…
Copy to ClipboardAugust 28th, 2008 at 5:39 pm -
Neenbyday said:
How i may contact admin this site? I have a question.
iijiiveiOctober 2nd, 2008 at 10:34 am -
Sajith M.R said:
You can mail me at: admin@sajithmr.com
October 2nd, 2008 at 3:22 pm -
MegranFuyis said:
i newbie plz how us the baton “add me”?
October 3rd, 2008 at 9:57 pm -
Narosponura said:
All greetings! I have fallen in love today:)))))
I wish to shout about love to all world !
Love this magnificent feeling:)))))October 27th, 2008 at 7:00 am -
Nick said:
Nice one, this is really handy - thanks very much indeed. I prefer the this.select(); route myself as it’s so simple..
Does anyone know an equally simple way to copy the contents to clipboard (in any browser)?
Thanks very much indeed.
November 6th, 2008 at 7:59 pm -
Sexualxe said:
Hello you forum best. And Bye. just test. .
:)
:)
:):)
:)
:)
November 7th, 2008 at 11:52 pm -
sairiurse said:
to: Admin - If You want to delete your site from my spam list, please sent url of your domain to my emai: stop.spam.today@gmail.com
And I will remove your site from my base within 24 hours
webmastegzNovember 15th, 2008 at 9:32 am -
HSCharles said:
I have a flash site
i’m looking for the script who shows google ads with flash.
how can i get it?November 16th, 2008 at 7:11 am




