Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
hai,
how to select and copy automatically when i click in the text box???

thanks in advance...
Posted
Updated 25-Dec-11 19:10pm
v2
Comments
CS2011 26-Dec-11 1:00am    
Select and copy what ? Can you explain your question a bit more ?
Sergey Alexandrovich Kryukov 26-Dec-11 2:12am    
This is clear, I think, but the idea is really bad -- please see my answer.
--SA
Sergey Alexandrovich Kryukov 26-Dec-11 2:04am    
Why? Why?!
--SA

in ur textbox use ... onFocus="javascript:this.select()
eg.
C#
<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)"

C#
function Copy(IDS) {
  document.getElementById("ur id ").value=document.getElementById(IDS).innerHTML;
}
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 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
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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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
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
 
Share this answer
 
Comments
mmvr2k11 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900