JavaScript Tip – Select All Text by Clicking on Text Field or Textarea Box

This script highlight all text in textarea or text field (input tag) by clicking on it.  It allows users to reduce their manual work.  For instance when users need to copy to the clipboard all text quickly or quickly delete the text from the field.  For example: to copy a piece of code or to delete a username and password on login web page.


The script is really very simple. Text field must have unique identifier, this indentifier will be passed to the SelectAll() function.
The function call only two methods: focus() and select().

<script type="text/javascript">
function SelectAll(id)

<textarea rows="3" id="txtarea" onClick="SelectAll('txtarea');" style="width:300px" >You can select all by clicking here</textarea>

Input TextBox:<br>
<input type="text" id="txtfield" onClick="SelectAll('txtfield');" style="width:300px" value = "You can select all by clicking here" />
Published in: on September 30, 2009 at 6:42 pm  Comments (2)  

The URI to TrackBack this entry is:

RSS feed for comments on this post.

2 CommentsLeave a comment

  1. Awesome blog!

    I thought about starting my own blog too but I’m just too lazy so, I guess Ill just have to keep checking yours out.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: