HTML Form
HTML form provides the way to collect information given by the users. It is reprresented by <form>...</form> tag. The basic structure of a form is given below:
Basic structure:
<form>
Elements of the form
</form>
Elements of the form
</form>
<input> Element
<input> is the most important element of HTML form. An input field can hold many types of value based on the type attribute. The default type is text.
Example:
<select> and <option> Element
The <select> element specifies a dropdown list and the list item is displayed using <option> element.
Example:
<select>
<option value="computer"> Computer </option>
<option value="laptop"> Laptop </option>
<option value="mobile"> Mobile </option>
</select>
<option value="computer"> Computer </option>
<option value="laptop"> Laptop </option>
<option value="mobile"> Mobile </option>
</select>
Run Example
Attributes of <select> Element
Here is some attributes which can be used in <select> element.
Attribute | Description |
---|---|
name | Specifies a name for the element. It identifes the value of name attribute if it sent to a server. |
size | For presenting a scrolling list it can be used. |
multiple | If this attribute is used a user can select multiple items from the list. |
Attributes of <option> Element
Here is some attributes which can be used in <option> element.
Attribute | Description |
---|---|
value | It can be used if an item is selected from the list. |
selected | An item can be initially selected by using this attribute. |
label | It is the alternative way to label the options. |
<textarea> Element
The <textarea> is also a text input field but it is used for multiline text.