Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Java script
hai,
         how to select and copy automatically when i click in the text box???
 
            thanks in advance...
Posted 25-Dec-11 19:58pm
Edited 25-Dec-11 20:10pm
v2
Comments
CS2011 at 26-Dec-11 1:00am
   
Select and copy what ? Can you explain your question a bit more ?
SAKryukov at 26-Dec-11 2:12am
   
This is clear, I think, but the idea is really bad -- please see my answer.
--SA
SAKryukov at 26-Dec-11 2:04am
   
Why? Why?!
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

in ur textbox use ... onFocus="javascript:this.select()
eg.
<asp:textbox id="txt1" runat="server" text="Abc" onfocus="javascript:this.select();" >
 
With this u can select the text of ur textbox
 
An onClick="Copy(this.id)"
 
function Copy(IDS) {
  document.getElementById("ur id ").value=document.getElementById(IDS).innerHTML;
}
  Permalink  
v3
Comments
SAKryukov at 26-Dec-11 2:10am
   
This is easy to implement, but think about it.
In my answer, I explained why such behavior means a real crime against the user -- please see.
(I did not vote against your answer anyway.)
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Have a look at Click... It's Copied![^]. Nice way to copy text.
 
Javascript Copy To Clipboard[^] might help you as well.
This[^] is another link that provides a similar solution.
  Permalink  
Comments
SAKryukov at 26-Dec-11 2:11am
   
Of course, this should work, this is easy. However...
In my answer, I explained why such behavior means a real crime against the user -- please see.
(I did not vote against your answer anyway.)
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

It's very bad to copy data to the clipboard when a user does not expect it. Imagine, you put some text to the clipboard from a text document and a Web site. Now, you want to add this text to your text box, but when you click on your text box and paste, you will find out that you old clipboard text did not appear, because it was replaced by the previous text from your text box. But you did not expect it. You maybe even closed original text document or a Web page.
 
From this example, do you understand what kind of crime you are going to commit against your user? If so, don't do it.
 
—SA
  Permalink  
Comments
mmvr2k11 at 26-Dec-11 2:16am
   
hai SAKryukov, thanks for u r reply. please understand my ques. my requirement is "some text in test box. the user come and click that text box, automatically tha text is selected and copy", the user just paste any whare in that text. i think u understand my requirement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 26 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100