413-03
413-03
Computing
HTML FORMS <FORM>
HTML form is used to collect user input. The user input is most
often sent to a server for processing.
The HTML <form> element is used to create an HTML form for
user input:
<form> form elements </form>
The <form> element is a container for different types of input
elements, such as: text fields, checkboxes, radio buttons, submit
buttons, etc.
The HTML <form> Elements
The HTML <form> element can contain one or more of the following
form elements:
<input>
<label>
<select>
<textarea>
<button>
<fieldset>
<legend>
<datalist>
<output>
<option>
The <label> Element
The <label> element defines a label for several form elements.
The <label> element is useful for screen-reader users, because the screen-
reader will read out loud the label when the user focus on the input
element.
The <label> element also help users who have difficulty clicking on very
small regions (such as radio buttons or checkboxes) - because when the
user clicks the text within the <label> element, it toggles the radio
button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of
the <input> element to bind them together.
The <input> Element
One of the most used form element is the <input> element.
The <input> element can be displayed in several ways, depending on the
type attribute.
<input type="button"> <input type="checkbox">
<input type="color"> <input type="date">
<input type="email"> <input type="file">
<input type="hidden"> <input type="image">
<input type="number"> <input type="password">
<input type="radio"> <input type="range">
<input type="reset"> <input type="search">
<input type="submit"> <input type="tel">
<input type="text"> <input type="time">
<input type="url"> <input type="week">
<input type="datetime-local"> Tip: The default value of the type
Input Type: text, password, submit, radio
<input type="text"> defines a single-line text input field
The value attribute specifies the value of an <input> element. The value
attribute is used differently for different input types:
For "button", "reset", and "submit" - it defines the text on the button
For "text", "password", and "hidden" - it defines the initial (default) value of
the input field
For "checkbox", "radio", "image" - it defines the value associated with the
input (this is also the value that is sent on submit)
Note: The value attribute cannot be used with <input type="file">.
Let’s create a form,
showing the
different input
types, using <form>
<label> & <input>
The <select> Element
The <select> element defines a drop-down list
The <option> elements defines an option that can be selected. By default, the first item in the
drop-down list is selected.
To define a pre-selected option, add the selected attribute to the option