- Forums
- Javascipt
- Onclick Select All Text In A Form Field Using Javascript and HTML
you will learn to just click inside the textarea and all the content text inside the field will be highlighted so you can copy and paste the text to your clipboard in your computer [805], Last Updated: Sat May 18, 2024
wallpaperama
Wed Sep 24, 2008
11 Comments
10277 Visits
onClick="select_text();"
ok. lets say i have a field, and as soon as you click on that field, you want all the text contained within the field to be selected automatically. well, you can do that with javascritp on this tutorial i will show you how you can do that.
here is the demonstration example
and here is the code i used:
<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>
hope you learned something from this short and useful tutorial
courtesy of www.webune.com
its working for me too
regards ali arshad.
https://www.wallpaperama.com/forums/javascript-onclick-select-all-text-in-a-form-field-t6378.html