Title: Javascript Copy Selected Text Box Select All Highlight Text Form Copy Paste
Description: javascript copy selected text box select all highlight text form copy paste Javascipt
Tags: javascript, copy, selected, text, box, select, all, highlight, text, form, copy, paste
Info: This Post Has Been Viewed 28938 Times SinceThu Jan 11, 2007 4:18 pm Author braker With 22 Replies #706

Javascript Copy Selected Text Box Select All Highlight Text Form Copy Paste

javascript is cool for making things in your browser, here is an example script to show you how you can put this on your site so that you don't have to hit the control + c on you keyboard to copy and paste the selected text in web forms.
here is a demo:



here is the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Select Copy Text Into Clipboard History with Javascript</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function copyit(theField) {
var selectedText = document.selection;
if (selectedText.type == 'Text') {
var newRange = selectedText.createRange();
theField.focus();
theField.value = newRange.text;
} else {
alert('Alert: Select The text in the textarea then click on this button');
}
}
// End -->
</script>
</head>

<body>
<p><strong>Select Copy Text Into Clipboard History with Javascript by Wallpaperama.com </strong></p>
<p><strong>Steps:</strong></p>
<p><strong>1. Hight the text inside the text area below</strong></p>
<p><strong>2. Click on the form button, this will copy the text into your clipboard (basically the same as hitting control + c on your keyboard)</strong></p>
<form name="javascript">

<input onclick="copyit(this.form.text_select)" type="button" value="Click Here to Copy the Highlighted Text" name="copy_button">
<p>
<textarea name="text_select" cols="35" rows="5" wrap="VIRTUAL">FREE WALLPAPERS An Amazing collection of High quality, high resolution wallpapers for your computer desktop for free. Download your favorite high resolution wallpaper for free at wallpaperama.com. Our free wallpapers include a large collection of wallpapers for your computer desktop. You will find only free wallpapers, no pop-up ads, no spam, no spyware only high quality free wallpapers for your computer background. Surf with confidence.
</textarea>
</form>
<div align="center">
<p align="left">If you learned or liked this script, we would appriciate puting a link of <a href="http://www.wallpaperama.com">wallpaperama.com</a> on your site. If you would like to exchange links with us, please <a href="http://www.wallpaperama.com/exchange-links.php">click here</a> to exchange links </p>
<p>Hosting By <a href="webune.com">Webune.com</a> </p>
</div>
</body>
</html>



Try it on your website, you will like it

here is another way to select the content in a field with javascript: check it out

javascript select all text form button

NOTE: This will work on Internet Explorer. I tried it on Mozilla Firefox but i did not do anything. i was hoping someone can help me with firefox?
Comments (22)
View Top Comments
Leave Your Comments...
#1
john:
1 month ago
#168868
john Sun Oct 23, 2011 9:52 pm
doesn't work
#2
Gautham:
4 months ago
#161024
Gautham Fri Jul 01, 2011 7:18 am
I recently stumbled across this blog link rindovincent.blogs where there is a simple way to copy text using JavaScript. Hope it will solve some of your problems.
#3
Sunil:
1 year ago
#147966
Sunil Sat Nov 20, 2010 10:14 pm
No It does not work at all in any browser.
Please go for another script...................
#4
tom:
1 year ago
#144571
tom Sat Sep 18, 2010 1:24 am
Hi I thought this my be Helpful,
This is another way for highlight html page contents , we will use the power of JQuery. It works on IE,Opera,FireFox & Safari Browsers.

Please read the Article Here:
sevenadoo.c
#5
genial:
2 years ago
#110040
genial Tue Jul 21, 2009 1:22 am
it's not works at all...!!! and also the demo thing up there :(

<a href=" 6raphic.blogspot ">genial</a>
#6
Pramod:
2 years ago
#109299
Pramod Tue Jul 14, 2009 3:05 am
can modify the code for this to work in firefox. this isnt working now
#7
Henk:
2 years ago
#103598
Henk Mon May 18, 2009 4:32 am
download java from original page then it will work see for yourself
#8
yogesh:
2 years ago
#99039
yogesh Thu Apr 02, 2009 5:39 am
i find the below link was useful supported multi-browser
<a href=" logiclabz /javascript/copy-to-clipboard-with- to clipboard javascript firefox ie</a>
#9
adnreas:
2 years ago
#84977
adnreas Fri Dec 05, 2008 11:41 pm
please teach me how to put a value in the textbox when we click a button using java script
#10
muniaswari:
3 years ago
#79081
muniaswari Sun Nov 02, 2008 7:54 pm
i want to bold the selected text of textarea box by clicking button using javascript
#11
Nishant:
3 years ago
#75577
Nishant Wed Oct 15, 2008 5:04 am
sorry to say but it did not work in firefox. can you send me a cross browser code for 'copy to clipboard' functionality.
#12
1
You:
3 years ago
#72903
You Mon Sep 29, 2008 2:25 am
this is dr.dre
#13
asd:
3 years ago
#65585
asd Fri Aug 08, 2008 10:15 pm
hey go to youtubeadds.blogspot to get more friends then nigahiga!!
#14
Carrie:
3 years ago
#64315
Carrie Fri Aug 01, 2008 6:27 am
did not work for me either...
#15
Angai:
3 years ago
#43144
Angai Tue Feb 26, 2008 1:39 am
its good.

i want to apply bold to the selected part of text in a textbox control.
is it possible? if so plz help me in coding.
#16
vishadev:
3 years ago
#36503
vishadev Tue Jan 15, 2008 5:04 am
without giving your full efforts to anything in your life, you can't justify your strengths and weakness....everybody lacks something in life....nobody is populated with each and every quality, a man should have? are really think like this.....so come forward, give upper hand to us...we will try to pull you for more details log on healthylivingpvtltd or e-mail to:enquiry at enbloc.biz (id no.393 )

#17
vishadev:
3 years ago
#36502
vishadev Tue Jan 15, 2008 5:03 am
without giving your full efforts to anything in your life, you can't justify your strengths and weakness....everybody lacks something in life....nobody is populated with each and every quality, a man should have? are really think like this.....so come forward, give upper hand to us...we will try to pull you for more details log on healthylivingpvtltd or e-mail to:enquiry at enbloc.biz (id no.393 )

#18
ashley:
3 years ago
#31859
ashley Sun Dec 16, 2007 4:29 am
thank you
#19
lion:
4 years ago
#26354
lion Fri Nov 02, 2007 10:53 am
did not work on my end, using the latest ie.
#20
muthaiah:
4 years ago
#25637
muthaiah Thu Oct 25, 2007 1:17 pm
the above code is does not support in firefox browser.so how to use above code.
Leave Your Comments...
Pages: 12
Share
| More