Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Making it easier to copy and paste text.



3:54 am on Mar 8, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month

I have a text input field I want to make easy for people to copy the contents. The input box contains a url which is longer than the length of the input field.

I know using JavaScript alone I can't make copy the value to clipboard on click. I have to use a Flash method like zeroclipboard which is something I don't want to do.

Currently I'm trying to make it pre-highlighted, and stays highlighted, so people just have to right click the text and copy it. How can I do this? And are there any other methods which are more preferred?

<input type="text" value="sample text..." />


7:27 am on Mar 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Are you referring to something link this that highlights the text onclick:

<script type="text/javascript">
function select_text()
var content=eval("document.myform.field");
<form method="post" action="" name="myform" >
<textarea name="field" rows="4" cols="40" onClick="select_text();">Click Inside the text area to select all
text within this form field </textarea>

This will not automatically copy the text, just highlight all of it.



11:18 am on Mar 8, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month

Yes, this is close to what I want. If you click on it it highlights it, but if you reclick it it will de-highlight it (which is default behavior). What I'm trying to do is make it so it's always highlighted.

Featured Threads

Hot Threads This Week

Hot Threads This Month