By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,918 Members | 1,557 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,918 IT Pros & Developers. It's quick & easy.

how to Select and copy text at single click ?

P: 21
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>javascript: Select All</title>
  3. <body>
  4. <center>
  5.   <form>
  6.     <textarea name="text_area" rows="10" cols="80">
  7.       blah blah blah blah blah blah blah 
  8.     </textarea>
  9.   <br>
  10.   <input type="button" value="Highlight Text" onClick="javascript:this.form.text_area.focus();this.form.text_area.select();">
  11.   </form>
  12. </center>
  13. </body>
  14. </html>
  15.  
Jun 4 '13 #1
Share this Question
Share on Google+
8 Replies


Dormilich
Expert Mod 5K+
P: 8,639
when you click into the textarea or when you click the button?
Jun 4 '13 #2

P: 21
when i click button. both hit at one time select and copy.
Jun 6 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
var text = this.form.text_area.value
Jun 6 '13 #4

P: 21
ok, so after applying this code, just text is selecting but not copying on clipboard.

Any new suggestions ??
Jun 7 '13 #5

Dormilich
Expert Mod 5K+
P: 8,639
ah, you want to copy it to the clipboard. you should have mentioned that.
Jun 7 '13 #6

P: 21
opps, sorry... please provide me the code.
Jun 7 '13 #7

Dormilich
Expert Mod 5K+
P: 8,639
there is not "that one code". there are various solutions that have different constraints. best search for "javascript clipboard", there you find lots of how-tos and maybe the one best suited for your need.
Jun 7 '13 #8

P: 9
try this one

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <SPAN ID="copytext" STYLE="height:150;width:162;background-color:pink">
  3. This text will be copied onto the clipboard when you click the button below. Try it!
  4. </SPAN>
  5.  
  6. <TEXTAREA ID="holdtext" STYLE="display:none;">
  7. </TEXTAREA>
  8. <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON> 
  9.  
  10. function ClipBoard()
  11. {
  12. holdtext.innerText = copytext.innerText;
  13. Copied = holdtext.createTextRange();
  14. Copied.execCommand("Copy");
  15. }
  16.  
  17. </SCRIPT>
Jun 7 '13 #9

Post your reply

Sign in to post your reply or Sign up for a free account.