Now that we have a basic understanding of the structure of an HTML form we can now look at each of the form elements in detail.
The syntax for creating a text object within a Form is as follows:
''event handling'' specifies what action to take when a particular event on the object is triggered. Events that can be triggered by the Text object are:
* '''onFocus''' - triggered when the text field gains focus (typically when the cursor is moved into the field to begin typing).
* '''onSelect''' - triggered when the user highlights text in the text field.
In addition to events, the Text object also has a number of methods that can be accessed to perform such tasks as selecting text and changing focus:
* '''focus()''' - sets focus and sets the cursor on the text field
* '''select()''' - Selects the text in the field so that when the user types all the existing text is replaced.
Now that we have covered some of the basics of building a FORM we can bring some of these concepts toegther in an example using the text object. The following example creates a Form containing a text field. When the user clicks in the text field the ''onFocus'' event is triggered which in turn calls the ''select()'' method to highlight the text in the field (Note that since we are referencing the current object when calling the ''select()'' method we can use the ''this'' keyword to refer to the current object):
// document.write ( document.myForm.elements.value );
var phone = document.getElementById("myText");
document.write ( phone.value );
<form action="" name="myForm">
<input type="TEXT" name="myText" id="myText" value="Some text" onFocus="this.select()"/>