Forms
Forms
HTML Forms are required to collect some data. A form will take input and then post it to a back-
end application such as CGI, ASP Script or PHP script etc. The back-end application will perform
required processing on the passed data based on defined business logic inside the application.
There are various form elements available like text fields, text-area fields, drop-down menus,
radio buttons, checkboxes, etc.
Form Controls
There are different types of form controls:
Single-line text input controls - This control is used for items that require only one line
of user input, such as search boxes or names. They are created using HTML <input> tag.
Password input controls - This is also a single-line text input but it masks the character
as soon as a user enters it. They are also created using HTMl <input> tag.
Multi-line text input controls - This is used when the user is required to give details that
may be longer than a single sentence. Multi-line input controls are created using HTML
<textarea> tag.
Following is the list of attributes for <input> tag for creating text field.
Attribute Description
type Indicates the type of input control and for text input control it will be set to text.
Used to give a name to the control which is sent to the server to be recognized and
name
get the value.
value This can be used to provide an initial value inside the control.
size Allows to specify the width of the text-input control in terms of characters.
Allows to specify the maximum number of characters a user can enter into the text
maxlength
box.
Checkbox Control
Checkboxes are used when more than one option is required to be selected. They are also created
using HTML <input> tag but type attribute is set to checkbox.
<select name="dropdown">
<option value="Maths" selected>Maths</option>
<option value="Physics">Physics</option>
</select>
Button Controls
You can create a clickable button using <input> tag by setting its type attribute to button. The
type attribute can take the following values:
<form>
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
<input type="button" name="ok" value="OK" />
<input type="image" name="imagebutton" src="/html/images/logo.png" />
</form>
HTML Comments
Comment is a piece of code which is ignored by any web browser. It is a good practice to add
comments into your HTML code. Comments help others understand your code and increases
code readability.