Jump to content

How To Select and Copy Text Field on Click?


Zinnia-Aster
 Share

Recommended Posts

Hey there everybody!I'm pretty new to javascript, and only know a few things. So I couldreally use some help here. What I want is a text field box that I can click on, and upon doing thatit should select all of the text and copy it at the same time. Like on Photobucket here: Findstuff on Photobucket .If you click on the code text field it copies it for you. Does anybody knowhow I can do this?I found this code:

<script type="text/javascript">function SelectAll(id){	document.getElementById(id).focus();	document.getElementById(id).select();}</script>Textarea:<br><textarea rows="3" id="txtarea" onClick="SelectAll('txtarea');" style="width:200px" >This text you can select all by clicking here </textarea>Input TextBox:<br><input type="text" id="txtfld" onClick="SelectAll('txtfld');" style="width:200px" value = "This text you can select all" />

And it is the closest thing I could find. But it doesn't copy it for you. Code was found here:Javascript-array.comThe reason I want to do this, is to have a list of smileys that has the code underneath of it. Then you just click the code and paste it whereveryou want. And also I will have a code to where you just click the smiley and insertit into the text field, but I think I have that one already. :) I need the other code for a specific reason.Any help would be greatly appreciated, guys! Thanks in advance! :)

Link to comment
Share on other sites

It can, but a lot of the suggestions I've seen only work in IE or use Flash objects.What if you instead copied the text to a hidden div? Or are you trying to copy text so that it is usable outside of the browser?

Link to comment
Share on other sites

It can, but a lot of the suggestions I've seen only work in IE or use Flash objects.What if you instead copied the text to a hidden div? Or are you trying to copy text so that it is usable outside of the browser?
Basically, I just want it to where when you click on the code, it copies it just like if you use the keyboard or mouse, and then you paste the code onto a different webpage. I noticed that too. Would the correct coding be flash then? I can use the above code,but I was just curious if there was way to copy on click.Thank you for your help! :)
Link to comment
Share on other sites

It would be pretty easy to abuse the Flash technique, I suspect. At Photobucket, they make it quite obvious what's happening. Now imagine embedding a little toy that AJAXes everybody's clipboard back to a database, matching it to any other data they can get from you. It's like the Browser History exploit the US papers have been writing about the last couple of days.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...