Forms and Frames in HTML Notes
Forms and Frames in HTML Notes
An HTML form is a section of a document which contains controls such as text fields, password
fields, checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the server for processing such
as name, email address, password, phone number, etc. .
For example: If a user want to purchase some items on internet, he/she must fill the form such as
shipping address and credit/debit card details so that item can be sent to the given address.
HTML Forms
Processing is done on the passes data at the back-end. There are various forms available like text
fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.
Syntax:
Tags Description
action Process your passed data.
method GET and POST methods are used to upload data.
Specifies the target window where the result of the script will be
target
displayed.
To specify how the browser encodes the data before it sends it to
enctype
the server.
HTML FORM CONTROLS
There are different types of form controls to collect data. They are:
It 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.
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.
It 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 CONTROL ATTRIBUTES
Single-line text input controls are required at only one line of user input(such as search boxes or
names). They can be created using HTML <input> tag.
Following is the list of attributes for <input> tag for creating a text field.
Attributes Description
type indicates the type of input control
name gives a name to the control
value provides an initial value inside the control
Example:
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
Address: <input type = "text" name = "address" />
</form>
</body>
</html>
HTML PASSWORD INPUT CONTROL ATTRIBUTES
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.
Following are the list of attributes for <input> tag for creating a text field.
Attributes Description
type indicates the type of input control
name gives a name to the control
value provides an initial value inside the control
size specifies the width of the text-input control in terms of characters
Example:
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form >
user name : <input type = "text" name = "user_name" />
<br>
Password: <input type = "password" name = "password" />
</form>
</body>
</html>
MULTIPLE-LINE TEXT INPUT CONTROLS ATTRIBUTES
Multiple-Line text input controls are used when the user needs to give details that may be
longer. Multi-line input controls are created using HTML <textarea> tag.
Attributes Description
name gives a name to the control
rows indicates the number of rows
size specifies the width of the text-input control in terms of characters
Example:
<html>
<body>
<form>
<textarea rows = "7" cols = "30" name = "description">
Enter the information
</textarea>
</form>
</body>
</html>
CHECK-BOX CONTROL ATTRIBUTES
Check-boxes are used when a user wants to select more than one option. They are created using
HTML <input> tag and the type attribute is set to a checkbox.
Attributes Description
<html>
<body>
<form>
<input type = "checkbox" name = "HTML" value = "on"> HTML
<input type = "checkbox" name = "CSS" value = "on"> CSS
</form>
</body>
</html>
RADIO BUTTON CONTROL ATTRIBUTES
Radio buttons are used when a user wants to select only one option out of many options. They
are also created using HTML <input> tag and the attribute type is set to the radio.
Attributes Description
type indicates the type of input control
Example:
<html>
<head>
<title>Radio Box Control</title>
</head>
<body>
<form>
<input type = "radio" name = "Gender" value = "Male"> Male
<input type = "radio" name = "Gender" value = "Female"> Female
</form>
</body>
</html>
BUTTON CONTROLS ATTRIBUTES
You can create a clickable button using <input>tag by setting its type attribute to button.
Following are the list of attributes for button controls
Attributes Description
Example:
<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/image.png" />
</form>
</body>
</html>
HTML CODES
Example:
<body>
<form>
Enter your name <br>
<input type="text" name="username">
</form>
</body>
Output:
HTML TextField Control
The type="text" attribute of input tag creates textfield
control also known as single line textfield control. The name
attribute is optional, but it is required for the server side
component such as JSP, ASP, PHP etc.
<form>
First Name: <input type="text" name="firstname"/><br/>
Last Name: <input type="text" name="lastname"/><br/>
</form>
Output:
HTML <textarea> tag in form
The <textarea> tag in HTML is used to insert multiple-line
text in a form. The size of <textarea> can be specify either
using "rows" or "cols" attribute or by CSS.
Example:
<html>
<head>
<title>Form in HTML</title>
</head>
<body>
<form>
Enter your address:<br>
<textarea rows="2" cols="20"></textarea>
</form>
</body>
</html>
Output:
Label Tag in Form
It is considered better to have label in form. As it makes the code
parser/browser/user friendly.
If you click on the label tag, it will focus on the text control. To do so, you need to
have for attribute in label tag that must be same as id attribute of input tag.
<form>
<label for="firstname">First Name: </label> <br/>
<input type="text" id="firstname" name="firstname"/>
<br/>
<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname"/>
<br/>
</form>
Output:
HTML Password Field Control
The password is not visible to the user in password field control.
<form>
<label for="password">Password: </label>
<input type="password" id="password" name="password"/> <br/>
</form>
Output:
HTML frames are used to divide your browser window into multiple sections where
each section can load a separate HTML document. A collection of frames in the
browser window is known as a frameset. The window is divided into frames in a
similar way the tables are organized: into rows and columns.
Disadvantages of Frames
There are few drawbacks with using frames, so it's never recommended to use
frames in your webpages −
• Some smaller devices cannot cope with frames often because their screen is not
big enough to be divided up.
• Sometimes your page will be displayed differently on different computers due
to different screen resolution.
• The browser's back button might not work as the user hopes.
• There are still few browsers that do not support frame technology.
Creating Frames
To use frames on a page we use <frameset> tag instead of <body> tag. The
<frameset> tag defines, how to divide the window into frames. The rows attribute of
<frameset> tag defines horizontal frames and cols attribute defines vertical frames.
Each frame is indicated by <frame> tag and it defines which HTML document shall
open into the frame.
<frame> has browser support in Chrome, Internet Explorer, Mozilla, Safari and Opera
Mini.
The different and some commonly used attributes in the frame are attributes such as
border, scrolling, src, name, etc.
TYPES OF FRAME TAG
Following are the different types of frame tags:
specified in 4 ways:
cols=”40%,20%,40%.”
We can also make use of the wildcard here (*) and let the wildcard take the
cols=”30%,*,30%”
2. Rows: The row attribute gives the horizontal frames. It specifies the rows in a
Eg: Rows=”10%,80%,10%’.
We can also set the height of each row as we had done in the case of columns
previously.
CREATE VERTICAL FRAMES:
<html>
<head>
<title>Frame tag</title>
</head>
<frameset cols="25%,50%,25%">
<frame src="frame1.html" >
<frame src="frame2.html">
<frame src="frame3.html">
</frameset>
</html>
CREATE HORIZONTAL FRAMES:
<html>
<head>
<title>Frame tag</title>
</head>
</frameset>
</html>