homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Making it easier to copy and paste text.
ocon




msg:4426322
 3:54 am on Mar 8, 2012 (gmt 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..." />

 

Marshall




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

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

ocon




msg:4426431
 11:18 am on Mar 8, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved