Click here to Skip to main content
12,076,657 members (49,333 online)
Rate this:
 
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 26-Dec-11 1:00am
   
Select and copy what ? Can you explain your question a bit more ?
SAKryukov 26-Dec-11 2:12am
   
This is clear, I think, but the idea is really bad -- please see my answer.
--SA
SAKryukov 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 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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 26 Dec 2011
Copyright © CodeProject, 1999-2016
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