Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript - OnClick Select All the Text from Textarea or Textbox Controls

Mar 14, 2013
Introduction

Here I will explain how to select all the text by click on textarea or textfield using JavaScript or Highlight All Text by Clicking on Text Field or Textarea in JavaScript.
 
Description:

In previous article I explained how to set watermark text for textbox using JavaScript, Remove duplicate values from string array in JavaScript, Disable drag and drop options in textbox or textarea controls, JavaScript show number of characters left in textbox and many articles relating to asp.net, jQuery, JavaScript. Now I will explain how to select all the text by click on textarea or textbox field using JavaScript.

To implement this we need to write the code as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Javascript onclick select all textarea</title>
<script type="text/javascript">
function SelectAll(id) {
document.getElementById(id).focus();
document.getElementById(id).select();
}
</script>
</head>
<body>
<div>
Enter Text:<br/>
<input type="text" id="txtfld" onclick="SelectAll('txtfld');" style="width:200px" value = "This text you can select all" /><br />
Textarea:<br/>
<textarea rows="5" cols="23" id="txtarea" onclick="SelectAll('txtarea');" style="width:200px" >Hi, Welcome to Aspdotnet-Suresh.com. I hope this site will give you better info </textarea>
</div>
</body>
</html>
Live Demo

To check for live demo try to put cursor in below textbox or textarea


Textbox:

Textarea:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

Veersh Dachepally said...

Very Good Articles......I like So Much....Very Helping to us

Unknown said...

it is not working in gridview textbox
please help

thankQ

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.