Jump to content

How To Select and Copy Text Field on Click?


Zinnia-Aster

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

I don't believe Javascript can copy text but it can sure select(highlight) the text for them so they can just press CTRL+C or right click>copy. If you look at the function you posted in that code it has it all there.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...