HTML Textbox

HTML textbox is the single line text entry element. It is used to let the users type a single line of text whose length can be restricted by specifying the maximum length. The example of data that can  be entered in an HTML textbox are name of a person, name of product, city name, search box etc.

Syntax – HTML Textbox

A textbox or simply a text field in an HTML form is created by using INPUT tag. The TYPE attribute is set to value “TEXT” to indicate that the control will accept only text/alphanumeric/symbol characters.

<INPUT TYPE=”TEXT”   [other attributes]>

Attributes- HTML Textbox

HTML Textbox control uses the following attributes.

TYPE

The TYPE attribute is used to define the type of control to be added in the HTML form.

ID

This attribute is used to give identification to the textbox in a web form element. The ID must be an alphanumeric string. The ID value for each field of web form must be unique. This ID is used in a script to manipulate the data entered by a user in the textbox.

NAME

The NAME attribute is used to give name to the textbox that is used to access its values by the associated php or asp script file since the data is passed as keyword-value pairs. It is like a variable name holding a value given by user.

SIZE

The SIZE attribute is used to define how much wide (in characters) the textbox is going to be. It’s the width of the textbox with which the textbox will be displayed to the visitor. If the user types more characters than the width of the textbox then these excess characters will be automatically left scrolled. The extra characters can be accessed by pressing the right arrow key.

MAXLENGTH

This attribute defines how many characters can be typed in the textbox. The textbox will inhibit the user to enter any more characters than the value set in MAXLENGTH attribute.

VALUE

The VALUE attribute represents the text entered by the user in the textbox. If you wish to have a default value to appear in the textbox when the HTML form renders in the browser window, you can specify it in the VALUE attribute.

Example using HTML Textbox
<BODY>
    <FORM  action="addperson.php" method="post">
    Your Name
	<BR>
    <input type="text"  Name="name" MAXLENGTH="50">
    <BR>
    
    Email ID
	<BR>
    <input type="text"  Name="email" SIZE="20">
	<BR>
    
    Job Designation
	<BR>
	<input type="text"  Name="jobd" SIZE="100">
	</FORM>		
</BODY>    
HTML Textbox example