Forms
Forms
INIT 7 FORMS
Sucture NOTES
70 Introtuction
11 Unit Objectives
1.2 Defining Forms
7.21 ACTION Attribute
7.22 METHOD Attribute
7.23 ENCTYPE Attribute
13 Form Controls
7.3.1 Drop Down List
7.3.2 Check Box
733 Radio Buttons
7.3.4 Text Field
7.3.5 TextArea
73.6 Password Field
7.3.7 Submit and Reset Buttons
74 Sample Forms
7.5 Summary
7.6 Key Terms
1.7 Answers to "Check Your Progress
7.8 Questions and Exercises
7.0 INTRODUCTION,,
HTML forms are that part of a Web page that allows the exchange of information
between the user and aWebsite, thereby, helping in creating the interactive environment.
Website.
Using forms, infomation can be collected from the users visiting a particular
The information gathered from the user can either be processed or stored for later use.
The most common examples of forms that are used on the Web are registration form,
application form order form.
SelfInstructional
108 Materia
CET mehod has an1advantage that it can be casily usedin scarch h engines, The Forms
Self-Instructional
Material 109
The syntax ofOPTION element is
<OPTION>.</OPTION>
The content specified within cach OPTION element is the value that is sent to th.
server. However, you can send other value to the server other than the value that
NOTES
displayed, by using the VALUE attribute ofthe OPTION element. For example, consi
these statements.
In these statements, the options First, Second, Third and Fourth wil be
displayed when the form is loaded but their values l,2, 3and 4are sent to the server.
SELECT clement has three attributes namely, NAME, SIZE and MULTIPIE
NAME Attribute
Every drop down control must be provided with a name which can be used to decode
khe option selected by the user. It is aunique name which acts like avariable name.n
The syntax for using NAME atribute is
<SELECT NAME = "CONTROL NAME">
Self-Insiructiona!
Material
eoutputof the HTML code is as follows:
Done My Computer
<OPTION>Red</0PTION>
<OPTION>Pink</OPTION>
<OPTION> Blue</OPTION>
<OPTION>Yellow </OPTION>
<OPTION>Green</OPTION>
</SELECT>
</FORM>
</BODY>
</HTM>
Self-Instru
Materia!
code is as follows:
The output of the HTM
Bed
Pink
FAVORITE COLOR IBlue
My Computer
)Done
MULTIPLE Attribute
one option; however, MULTI PLE attribute
In the drop down list, the user can select only multiple options. User can select contiguos
ofSELECT element enables the user to select
clicking the first and last option
multiple options by holding down the SHIFT key and select non-contiguous multiple
can also
from the list of options to be selected)Userchcking
options by holding dewn the SHIFT key and the desired options from the list.
The syntax for using MULTIPLE attribute is
<SELECT MULTIPLE>|
ofMULTIPLE attribute
Example 7.3: An HTML code to demonstrate the use
<HTML>
<HEAD>
<TITLE>Drop Down List</TITLE>
</HEAD>
<BODY>
METHOD= "POST#
<FORM ACTION= "/CGI-BIN/MYCGI. PL"
<B>FAVORITE COLOR</B>
<SELECT NAME= "FAVORITE COLOR" MULTIPLE>
<OPTION>Red</OPTION>
<OPTION>Pink</OPTION>
<OPTION>Blue</OPTION>
<OPTION>Yellow</OPTION>
<OPTION>Green</OPTION>
</SELECT>
</FORM>
</BODY>
</HML>
Self-Instructional
Material
the HTML
outputof code is as follows: Forms
AFORITE COLORYellow
IaDone
My Computer
heck box is atwo state control having states true, (checked) and false (unchecked).
er can create more than one check box and can select any number of check boxes.
henthe fom is submitted, values of only selected check boxes are sent as data to the
erve.Check box can be created by using INPUT element along with its TYPE attribute.
(The syntax for creating check box is
<INPUT TYPE = "Checkbox">
The value ofcheck box can be specifiedby using VALUE attribute ofthe INPUT
cenent. The default status of check box is unchecked, which can be changed to checked
by using the CHECKED attribute. Note that more than one check box can have same
name. In such a case, those check boxes act like a drop down list in which more than
one option can b¹ selected.
ExampleA: An HTML code to demonstrate the creation of check box control
<HIML>
<HEAD>
<TITLE> Check Box</TITLE>
</HEAD>
<BODY>
FORM ACTION = "/CGI-BIN/MYCGI. PL" METHOD="POST">
<B> Which of the following is your favorite color? </B>
<BR>>
Red
<INPUT TYPE- "Checkbox" NAME= "Color" VALUE= "Red">
<BR>
Pink
Self-Instructional
Material 117
"Pink+
TYPE= "Checkbox" NAME= *Color" VALUE=
<INPUT
CHECKED>
<BR>
Yellow VALUE= "Yell.
TYPE = "Checkbox" NAME= "Color"
<INPUT
NOTES
<BR>
"Bluers
Blue
"Checkbox" NAME= "Color" VALUE=
<INPUT TYPE=
</FORM>
<HR>
</BODY>
</HTML>
HTML code is as
follows:
The output of the
coler?
Which of the following is yor fvorite
Red
Yelbw
Bhe
aDone
My Computer
Like check box, radio button is also a two- state control. However, unlike check boxes,
0. only one radio button can be selected at a time among several radio buttons|Selecting
he radio button automatically deselects previously selected radio button. Radio buttons
are used when options are to be defined mutually exclusive. It is also created by using
INPUT element along with its TY PE attribute.
KJhe syntax for creating radio button is
<INPUT TYPE = "Radio>
Like check boxes, radio buttohs can also be assigned different values using VALUE
attribute. The value of the selected radio button is sent as data to the server.
Example 7.5: An HTML code to demonstrate the creation of radiobutton control
<HIM>
<HEAD>
SelfInstructional
4 Material
AITLE>Radio Button<//TITLE>
HEAD>
ACTION "/CGI-
«FORN
|=
of the
-BIN/MYCGI. PL" METHOD= "POST">
CB> Which following is your favorite color?</B> NO
<BR>
Yellow
TYDrT TYPE = "Radio" NAME= "color* VALUB=
"Yellow*>
<BR>
Blue
TNPUT TYPE= "Radio" NAME= "color" VALUE= "Blue">
/FORM>
<R>
</BODY>
</HTM>
The output of the HTML code is as follows:
Sexch SFavortes bw
eDone My Coputer
Permanent address
<INPUT TYPE="Text NAME="Useraddress" SIZE="30"
MAXLENGTH="50">
<BR>
City
<INPUT TYPE= "Text" NAME= "Usercity" VALUE=
"New Delhi"
READONILY>
Contact no.
<INPUT TYPE= "Text" NAME=
READONLY>
"Usercontact VALUE= "011
</FORM
</BODY>
</HTML
nstructional
ial
HTMI.. code is as follows:
the
ceultputof
net Explorer
Feld Microsoft Inter
FTent
F ew Favctes Iools Hep
NO
Sexch Favortes )
yalia
My Computer
by using READONLY
. Toxt in the text field control can be made read-only
atribute.
13.5 Text Area
amount of
is a multi-line text input field that allows the users to enter large
Tett area text area has two attributes namely,
ROWS
than one line of text). The
ual data (more text that can be
and COLS. ROWS attribute is used COLS to specify the number of rows of the number of
attribute is used to specify
entered in the text area, whereas control can be created
in the text area. Text area
characters per line that can be entered
element.
by using TEXTAREA
sytax for creating the text area is
The<TEXTAREA>..</TEXTAREA>
control
A: An HTML code to demonstrate the creation of text area
Example
<HIM>
<HEAD>
<TITLE Textarea Control</TITLE>
</HEAD>
<BODY>
="/CGI-BIN/MYCGI. PL" METHOD"POST">
<FORM AcTION
join our Company? </P>
<P> Why do you want to
ROWS= "5" COLS= "40>
<TEXTAREA NAME= "Userviews"
here
WI1te your answer
</TEXTAREA>
</FORM
</BODY>
Self-tnstructiona
Material
The output of the HTML code is as follows:
Done My Compter
To limit the size and specify the maximum uumber of characters that auser can
enter in apassword field, SIZE and MAXLENGTH attributes can be used, respectively.
Example 7.8: An HTML code to demonstrate the creation of password field
<HTM>
<HEAD>
<TITLE> Password field </TITLE>
</HEAD>
<BODY>
<FORM ACTION= "/CGI-BIN/MYCGI. PL" METHOD= "POST">
Enter your name
<INPUT TYPE = "Text" NAME= "Username" SIZE = "20">
<BR>
Enter your password
<INPUT TYPE = "PASSWORD" NAME= "Userpassword SIZE=
"10" MAXLENGTH = "15">
</FORM>
</BODY>
</HTML>
Self-Instructional
Material
the HTML ode is as
outputof follows:
The
SPaswordfietd Microsoft Internet xploter
NOTES
My Compter
apore
<BR>
Sel-lnstructional
Material
Enter your password
<INPUT TYPE "PASSWORD" NAME= "Userpassword" SIZR=
"10" MAXLENGTH "15">
<BR>
<INPUT TYPE= "SUBMIT" NAME= "Send" VALUE= "Send,
NOTES
<INPUT TYPE = "RESET" NAME = "Clear" VALUE- "Start
Again">
</FORM
</BODY>
</HIM>)
The output of the HTML code is as
follows:
My Computer
Done
Self-Instructional
Material
mn ALIGN=
<TD ALIGN= "Left"> "Left"><B>First Names/B></TD>
<INPUT TYPE= *Text" NAME= T1"
TR>
SIZE= 20"></TD>
TR> NOT
eD ALIGN= *
<TD ALIGN= "Left"> Left"><B>Last Name</B></TD>
CINPUT TYPE= "Text" NAME=
T1" SIZE= "20">
</TD>
</TR>
<TR>
<TD ALIGN=
"Left"><B>Pernanent Address</B></TD>
<TD ALIGN= "Left">
<TR>
<TD ALIGN=
TD> "Left"><B>Correspondence Address</B></
<TD ALIGN= "Left">
<TEXTAREA ROWS= "2" NAME= "S1" COLS= "20"><l
TEXTAREA> </TD>
</TR>
<TR>
<TD ALIGN= "Left"
><B>City</B></TD>
<TD ALIGN=Left">
<INPUT TYPE- "Text" NAME= "T1 SIZE= "20">
</TD>
</TR>
<TR>
<TR>
Selt
<TR>
<TD ALIGN= "Left"><B> POST
APPLIED FOR</B></T
<TD>
<SELECT NAME : "POST">
NOTES
<OPTION VALUE= "1"> HR </OPTION
<OPTION VALUE= "2"> MARKETING
EXEcUTIVE </OPTIOAX
<OPTION VALUE= "3"> ASSISSTANT MANAGER </OPTION
<OPTION VALUE= "4"> CONTENT WRITER
</0PTION
</SELECT>
</TD>
</TR>
</TABLE>
<P>Write a brief summary of your experiences with
previous companies in this box.
<TEXTAREA ROWS= "5" NAME= "S1" COLS= "30"></TEXTAREA
</P>
<P ALI GN="Center">
<INPUT TYPE= "Submit" VALUE= "Submit NAME= "B1>
<INPUT TYPE= "Reset" VALUE= "Reset" NAME= "B2">
</P>
</FORM>
</BODY>
</HTIML>
The output of the HTML code is as follows:
DAppli atbnfo M bs1t Internwt bporet
Fe Edt Mew Fgrartes Ioos
CONTENTWRITER
FLLYOURbtzALS
endece AAt
Clty
OMALE QFEMALE
POSTAPUn FOR MAPKETNG EECTME
MAPKISTIeFSER
ASSISSTANT MAN
ANAGER
CONTENT WRTER
Submit Rasgt
IDone
My Conoue
tructional