Ultra fast cheap  linux and windows hosting
javascript tutorial Browse Basic JavaScript Tutorial
Browse JavaScript Script resources
Browse javascript FAQS

javascript tutorial
buy template
Home >> Tutorials >> Advanced javascript tutorials

Javascript - Select all text from field/textarea

This example will show you how to select all text from your textarea within your forms. You can use any of the 3 options, link, button, or image. See the example below.

Select text from text field

Step 1: Put the following JavaScript in the HEAD of your HTML document that will do the selection. In the function first set the focus to the form field passed and then select the text within it.

Select the text from textarea

Step 2: The second thing you need to do is setup the link that will pass the form field data to the JavaScript.

Add a text link to select the text

<form name="form1">
<input type="text" name="field1" size=30 value="hello" maxlength=50>
<a href="javascript:SelectTheText(document.form1.field1)">Click to Select</a>

The "form1" and the "field1" values tell the JavaScript what form and field/textarea will be selected.

Add a button to select the text

Add the following code between <form> </form>

<input type="submit" value="Grab Text" onClick='SelectTheText(document.form1.field1);'>

Add an image link to select the text

Add the following code between <form> </form>

<input type="image" src="image.gif" onClick='SelectTheText(document.form1.field1);'>

Page contents: itechies.net - Learn how to Select all text in a form field using javascript.
javascript tutorial
javascript book
Buy this book