The Set School Computer HTML Forms Class Vii
The Set School Computer HTML Forms Class Vii
COMPUTER
HTML FORMS
CLASS VII
HTML FORMS
Page 1 of 8
elements the information of an user is
HTML Form is a document
submitted on a web server.
which stores information of a user on a
web server using interactive controls. HTML Forms are required, when you want
An HTML form contains different kind to collect some data from the site visitor.
For example, during user registration you
of information such as username,
would like to collect information such as
password, contact number, email id etc. name, email address, credit card, etc.
A form will take input from the site visitor
and then will post it to a back-end
application such as 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.
The elements used in an HTML form
are check box, input box, radio buttons, There are various form elements available
like text fields, text area fields, drop-down
submit buttons etc. Using these menus, radio buttons, checkboxes, etc.
Form Attributes
Apart from common attributes, following is a list of the most frequently used form attributes −
Sr.No Attribute & Description
1 action
Backend script ready to process your passed data.
2 method
Method to be used to upload data. The most frequently used are GET and POST methods.
3 target
Specify the target window or frame where the result of the script will be displayed. It
takes values like _blank, _self, _parent etc.
4 enctype
You can use the enctype attribute to specify how the browser encodes the data before it
sends it to the server. Possible values are −
Page 2 of 8
Text Input Controls
There are three types of text input used on forms −
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.
Example
Here is a basic example of a single-line text input used to take first name and last name −
<!DOCTYPE html>
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
First name: <input type = "text" name = "first_name" />
<br>
Last name: <input type = "text" name = "last_name" />
</form>
</body>
</html>
Attributes
Following is the list of attributes for <input> tag for creating text field.
Sr.No Attribute & Description
1 type
Indicates the type of input control and for text input control it will be set to text.
2 name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
Page 3 of 8
3 value
This can be used to provide an initial value inside the control.
4 size
Allows to specify the width of the text-input control in terms of characters.
5 maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
Example
Here is a basic example of a single-line password input used to take user password −
<!DOCTYPE html>
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form >
User ID : <input type = "text" name = "user_id" />
<br>
Password: <input type = "password" name = "password" />
</form>
</body>
</html>
Attributes
Following is the list of attributes for <input> tag for creating password field.
Sr.No Attribute & Description
1 type
Indicates the type of input control and for password input control it will be set
to password.
2 name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
3 value
This can be used to provide an initial value inside the control.
Page 4 of 8
4 size
Allows to specify the width of the text-input control in terms of characters.
5 maxlength
Allows to specify the maximum number of characters a user can enter into the text box.
Attributes
Following is the list of attributes for <textarea> tag.
Sr.No Attribute & Description
1 name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
2 rows
Indicates the number of rows of text area box.
3 cols
Indicates the number of columns of text area 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..
Example
Here is an example HTML code for a form with two checkboxes −
<!DOCTYPE html>
<html>
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
<input type = "checkbox" name = "maths" value = "on"> Maths
<input type = "checkbox" name = "physics" value = "on"> Physics
</form>
</body>
</html>
Attributes
Following is the list of attributes for <checkbox> tag.
Sr.No Attribute & Description
1 type
Indicates the type of input control and for checkbox input control it will be set
to checkbox..
Page 5 of 8
2 name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
3 value
The value that will be used if the checkbox is selected.
4 checked
Set to checked if you want to select it by default.
1 type
Indicates the type of input control and for checkbox input control it will be set to radio.
2 name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
3 value
The value that will be used if the radio box is selected.
4 checked
Set to checked if you want to select it by default.
Page 6 of 8
A select box, also called drop down box which provides option to list down various options in
the form of drop down list, from where a user can select one or more options.
Example
Here is example HTML code for a form with one drop down box
<!DOCTYPE html>
<html>
<head>
<title>Select Box Control</title>
</head>
<body>
<form>
<select name = "dropdown">
<option value = "Maths" selected>Maths</option>
<option value = "Physics">Physics</option>
</select>
</form>
</body>
</html>
Attributes
Following is the list of important attributes of <select> tag −
Sr.No Attribute & Description
1 name
Used to give a name to the control which is sent to the server to be recognized and get the
value.
2 size
This can be used to present a scrolling list box.
3 multiple
If set to "multiple" then allows a user to select multiple items from the menu.
Following is the list of important attributes of <option> tag −
Sr.No Attribute & Description
1 value
The value that will be used if an option in the select box box is selected.
2 selected
Specifies that this option should be the initially selected value when the page loads.
3 label
An alternative way of labeling options
<!DOCTYPE html>
<html>
Page 7 of 8
<head>
<title>Simple registration form</title>
<h1>Registration</h1>
<form action="/">
<hr>
<div class="account-type">
<input type="radio" value="none" id="radioOne" name="account" checked/>
<label for="radioOne" class="radio">Personal</label>
<input type="radio" value="none" id="radioTwo" name="account" />
<label for="radioTwo" class="radio">School</label>
</div>
<hr>
<label id="icon" for="name"><i class="fas fa-envelope"></i></label>
<input type="text" name="name" id="name" placeholder="Email" required/>
<label id="icon" for="name"><i class="fas fa-user"></i></label>
<input type="text" name="name" id="name" placeholder="Name" required/>
<label id="icon" for="name"><i class="fas fa-unlock-alt"></i></label>
<input type="password" name="name" id="name" placeholder="Password" required/>
<hr>
<div class="gender">
<input type="radio" value="none" id="male" name="gender" checked/>
<label for="male" class="radio">Male</label>
<input type="radio" value="none" id="female" name="gender" />
<label for="female" class="radio">Female</label><br>
<select name = "dropdown">
<option value = "Maths" selected>Maths</option>
<option value = "Physics">Physics</option>
</select>
</div>
<hr>
<p>By clicking Register, you agree on our <a href="https://www.w3docs.com/privacy-
policy">Privacy Policy for W3Docs</a>.</p>
<button type="submit" href="/">Submit</button>
</div>
</form>
</div>
</body>
</html>
Page 8 of 8