input tag (XHTML 1.1)
form controlTopics
The input tag serves as a common tag for several types of form elements. By using the type attribute, you specify which kind of control you want. The most common is the text type, which is rendered as a singleline text input field. Here's an example:
<input type="text" name="textbox1" />
In your browser, code like that will be rendered like this:
The type attribute
The type attribute allows the input tag to be a multipurpose tag for rendering different types of controls.
text
A standard input field for single lines of text:
password
Just like the text box, but characters are masked:
hidden
A hidden text box, for submitting invisible information along with the form (you can see it in the source):
checkbox
A checkbox allows the user to select multiple choices: Checkbox
radio
A radiobutton allows the user to select between a range of values: Radiobutton
submit
A submit control will submit the surrounding form:
reset
A reset control will reset all the fields of the surrounding form to the initial value:
button
A button control won't do anything by it self, and is mostly used for scripting purposes:
image
An image control allows you to create a button rendered as an image, using the src attribute:
file
The file control is for doing file uploads. The control only allows the user to select a local file - you will have to handle the processing of the file yourself:
Attributes
| Attribute | Deprecated | Required | Description |
|---|---|---|---|
| accept | list of MIME types for file upload | ||
| align | X | vertical or horizontal alignment | |
| alt | short description | ||
| checked | for radio buttons and check boxes | ||
| class | space-separated list of classes | ||
| dir | direction for weak/neutral text | ||
| disabled | unavailable in this context | ||
| id | document-wide unique id | ||
| ismap | use server-side image map | ||
| lang | language code | ||
| maxlength | max chars for text fields | ||
| name | submit as part of form | ||
| readonly | for text and passwd | ||
| size | specific to each type of field | ||
| src | for input fields with images | ||
| style | associated style info | ||
| tabindex | position in tabbing order | ||
| title | advisory title | ||
| type | specifies the type of input control to be rendered | ||
| usemap | use client-side image map | ||
| value | Specify for radio buttons and checkboxes |
Events
| Event | Description |
|---|---|
| onblur | the element lost the focus |
| onchange | the element value was changed |
| onclick | a pointer button was clicked |
| ondblclick | a pointer button was double clicked |
| onfocus | the element got the focus |
| onkeydown | a key was pressed down |
| onkeypress | a key was pressed and released |
| onkeyup | a key was released |
| onmousedown | a pointer button was pressed down |
| onmousemove | a pointer was moved within |
| onmouseout | a pointer was moved away |
| onmouseover | a pointer was moved onto |
| onmouseup | a pointer button was released |
| onselect | some text was selected |