Welcome to WebmasterWorld Guest from 54.196.233.208

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)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:222
votes: 0


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)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 4, 2001
posts:2143
votes: 7


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");
content.focus();
content.select();
}
</script>
<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>
</form>

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

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

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:222
votes: 0


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.