KEMBAR78
Unit 5 - Module 3: 5.3. HTML Forms | PDF | Html | Html Element
0% found this document useful (0 votes)
553 views12 pages

Unit 5 - Module 3: 5.3. HTML Forms

HTML forms are used to collect user input on web pages. They contain various form controls like text fields, checkboxes, radio buttons, and submit buttons. The <form> tag is used to create an HTML form and includes attributes like action and method. Common form controls include single-line and multi-line text fields, password fields, checkboxes, radio buttons, drop-down menus, file uploads, and buttons. Hidden form controls can also store hidden data submitted to the server. Forms allow users to enter information and submit it to a server for processing.

Uploaded by

yaswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
553 views12 pages

Unit 5 - Module 3: 5.3. HTML Forms

HTML forms are used to collect user input on web pages. They contain various form controls like text fields, checkboxes, radio buttons, and submit buttons. The <form> tag is used to create an HTML form and includes attributes like action and method. Common form controls include single-line and multi-line text fields, password fields, checkboxes, radio buttons, drop-down menus, file uploads, and buttons. Hidden form controls can also store hidden data submitted to the server. Forms allow users to enter information and submit it to a server for processing.

Uploaded by

yaswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Unit 5 -Module 3

5.3. HTML Forms


HTML Forms are required to collect different kinds of user inputs, such as contact details like
name, email address, phone numbers, or details like credit card information, etc.

Forms contain special elements called controls like input box, checkboxes, radio-buttons, submit
buttons, etc. Users generally complete a form by modifying its controls e.g. entering text,
selecting items, etc. and submitting this form to a web server for further processing.

The HTML <form> tag is used to create an HTML form and it has following syntax:

<form action="Script URL" method="GET|POST">

form elements like input, textarea etc.

</form>

Form Attributes
Apart from common attributes, following is a list of the most frequently used form attributes:

Sr.No Attribute & Description


action
1
Backend script ready to process your passed data.
method
2
Method to be used to upload data. The most frequently used are GET and POST methods.

HTML Form Controls


There are different types of form controls that you can use to collect data using HTML form:

 Text Input Controls


 Checkboxes Controls
 Radio Box Controls
 Select Box Controls
 File Select boxes
 Hidden Controls
 Clickable Buttons
 Submit and Reset Button
5.3.1. Text Input Controls
There are 3 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.

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.

Here is a basic example of a single-line text input used to take first name and last name:

Example
<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>
Result

Attributes
Following is the list of attributes for <input> tag for creating text field.
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 but type attribute is set to password.

Password: <input type="password" name="password" />

Example
<!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>
Result

Attributes
Following is the list of attributes for <input> tag for creating password field.

Multiple-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
<!DOCTYPE html>
<html>

<head>
<title>Multiple-Line Input Control</title>
</head>

<body>
<form>
Description : <br />
<textarea rows = "5" cols = "50" name = "description">
Enter description here...
</textarea>
</form>
</body>

</html>
Result

Attributes

5.3.2. 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
<!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>
Result

Attributes

5.3.3. Radio Button Control


Radio buttons are used when out of many options, just one option is required to be selected.
They are also created using HTML <input> tag but type attribute is set to radio.

Example
<!DOCTYPE html>
<html>

<head>
<title>Radio Box Control</title>
</head>

<body>
<form>
<input type = "radio" name = "subject" value = "maths"> Maths
<input type = "radio" name = "subject" value = "physics"> Physics
</form>
</body>

</html>
Result
Attributes

5.3.4. Select Box Control


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
<!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>
Result

Attributes

Following is the list of important attributes of <select> tag −

Sr.No Attribute & Description


name
1
Used to give a name to the control which is sent to the server to be recognized and get the
value.
size
2
This can be used to present a scrolling list box.
multiple
3
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


Value
1
The value that will be used if an option in the select box box is selected.
selected
2
Specifies that this option should be the initially selected value when the page loads.
Label
3
An alternative way of labeling options

5.3.5. File Upload Box


If you want to allow a user to upload a file to your web site, you will need to use a file upload
box, also known as a file select box. This is also created using the <input> element but type
attribute is set to file.

Example
<!DOCTYPE html>
<html>

<head>
<title>File Upload Box</title>
</head>

<body>
<form>
<input type = "file" name = "fileupload" accept = "image/*" />
</form>
</body>

</html>
Result
Attributes

5.3.6. Button Controls


There are various ways in HTML to create clickable buttons. You can also create a clickable
button using <input> tag by setting its type attribute to button. The type attribute can take the
following values:

Example
<!DOCTYPE html>
<html>

<head>
<title>File Upload Box</title>
</head>

<body>
<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>
</body>

</html>
Result

image
5.3.7. Hidden Form Controls
Hidden form controls are used to hide data inside the page which later on can be pushed to the
server. This control hides inside the code and does not appear on the actual page. For example,
following hidden form is being used to keep current page number. When a user will click next
page then the value of hidden control will be sent to the web server and there it will decide which
page has be displayed next based on the passed current page.

Example
<!DOCTYPE html>
<html>

<head>
<title>File Upload Box</title>
</head>

<body>
<form>
<p>This is page 10</p>
<input type = "hidden" name = "pagename" value = "10" />
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</form>
</body>

</html>
Result

QUIZ:
1. In HTML form <input type="text"> is used for
A. One line text
B. Block of text
C. One paragraph
D. None
2. For creating a drop-down list in HTML forms which element is suitable?
A. <list>
B. <dropdown>
C. <select>
D. All of above
3. While submitting a form method attribute specifies what?
A. Get and Post method
B. Get and Set method
C. Put and Set method
D. Get and Host method
4. Default method while submitting a form is
A. Put method
B. Post method
C. Set method
D. Get method
5. Cols attribute in forms text area specifies what?
A. The visible width of a text area
B. The visible number of lines in a text area
C. Size of a text area
D. Size of a text field
6. <fieldset> element in HTML forms is used for
A. Group of related data
B. Group of irrelevant data
C. Text field
D. None

UNSOLVED PROBLEMSET
1. Create below mention page
2. Create the below mentioned page
3. Create the below mentioned page

You might also like