2 - 3 - Form Tag & Input Elements
2 - 3 - Form Tag & Input Elements
Forms add the ability to web pages to not only provide the person
viewing the document with dynamic information but also to obtain
information from the person viewing it, and process the information.
Objectives:
Upon completing this section, you should be able to
1. Create a FORM.
2. Add elements to a FORM.
3. Describe the purpose of a CGI Application.
4. Specify an action for the FORM.
Forms work in all browsers.
Forms are Platform Independent.
75
Forms
To insert a form we use the <FORM></FORM> tags. The rest of the form
elements must be inserted in between the form tags.
<HTML> <HEAD>
<TITLE> Sample Form</TITLE>
</HEAD>
<BODY BGCOLOR=“FFFFFF”>
<FORM ACTION = http://www.xnu.com/formtest.asp>
<P> First Name: <INPUT TYPE=“TEXT” NAME=“fname” MAXLENGTH=“50”> </P>
<P> <INPUT TYPE=“SUBMIT” NAME=“fsubmit1” VALUE=“Send Info”> </P>
</FORM>
</BODY> </HTML>
76
<FORM> element attributes
ACTION: is the URL of the CGI (Common
Gateway Interface) program that is going to accept
the data from the form, process it, and send a
response back to the browser.
METHOD: GET (default) or POST specifies which
HTTP method will be used to send the form’s
contents to the web server.
NAME: is a form name used by VBScript or
JavaScripts.
TARGET: is the target frame where the response
page will show up.
77
Form Elements
82
Sami Ali
Al al-Bayt University
83
Form Elements
<INPUT> Element’s Properties
VALUE= The data associated with the variable name to be passed to the CGI application
86
Output
87
Password
Password: Used to allow entry of passwords.
<INPUT TYPE= " PASSWORD " >
Browser will display
Text typed in a password box is starred out in the browser
display.
Password boxes use the following attributes:
TYPE: password.
SIZE: determines the size of the textbox in characters.
MAXLENGHT: determines the maximum size of the password in
characters.
NAME: is the name of the variable to be sent to the CGI
application.
VALUE: is usually blank.
88
Example on Password Box
<HTML><HEAD>
<TITLE>Form_Password_Type</TITLE></HEAD>
<BODY>
<h1> <font color=red>To Access, Please
enter:</font></h1>
<FORM name="fome2" Action="url" method="get">
User Name: <INPUT TYPE="TEXT" Name="FName"
SIZE="15" MAXLENGTH="25"><BR>
Password: <INPUT TYPE="PASSWORD"
NAME="PWord" value="" SIZE="15”
MAXLENGTH="25"><BR>
</FORM></BODY> </HTML>
89
Output
90
Hidden
Hidden: Used to send data to the CGI application that
you don’t want the web surfer to see, change or have
to enter but is necessary for the application to process
the form correctly.
<INPUT TYPE=“HIDDEN”>
Nothing is displayed in the browser.
Hidden inputs have the following attributes:
TYPE: hidden.
NAME: is the name of the variable to be sent to the
CGI application.
VALUE: is usually set a value expected by the CGI
application.
91
Check Box
Check Box: Check boxes allow the users to select more
than one option.
<INPUT TYPE=“CHECKBOX”>
Browser will display
92
<HTML> <HEAD><TITLE>CheckBoxType</TITLE> </HEAD>
<BODY>
<h1> <font color=green>Please check one of the
following</font></h1>
<FORM name="fome3" Action="url" method="get">
<font color=red> Select Country: </font><BR>
jordan:<INPUT TYPE="CheckBox" Name="country"
CHECKED><BR>
Yemen<INPUT TYPE="CheckBox" Name="country"><BR>
Qatar:<INPUT TYPE="CheckBox" Name="country"><BR> <BR>
<font color=blue>Select Language:</font><BR>
Arabic:<INPUT TYPE="CheckBox" Name="language"
CHECKED><BR> English:<INPUT TYPE="CheckBox"
Name="language"><BR>
French:<INPUT TYPE="CheckBox" Name="language">
<BR></FORM> </BODY></HTML>
93
Radio Button
Radio Button: Radio buttons allow the users to select
only one option.
<INPUT TYPE=“RADIO”>
Browser will display
94
<HTML> <HEAD><TITLE>CheckBoxType</TITLE> </HEAD>
<BODY>
<h1> <font color=green>Please check one of the
following</font></h1>
<FORM name="fome3" Action="url" method="get">
<font color=red> Select Country: </font><BR>
jordan:<INPUT TYPE= "RADIO" Name="country"
CHECKED><BR>
Yemen<INPUT TYPE="RADIO " Name="country"><BR>
Qatar:<INPUT TYPE="RADIO" Name="country"><BR> <BR>
<font color=blue>Select Language:</font><BR>
Arabic:<INPUT TYPE="RADIO" Name="language"
CHECKED><BR> English:<INPUT TYPE=" RADIO "
Name="language"><BR>
French:<INPUT TYPE=" RADIO " Name="language">
<BR></FORM> </BODY></HTML>
95
<HTML><HEAD>
<TITLE>RADIOBox</TITLE> </HEAD>
<BODY>
Form #1:
<FORM>
<INPUT TYPE="radio" NAME="choice" VALUE="one"> Yes.
<INPUT TYPE="radio" NAME="choice" VALUE="two"> No.
</FORM>
<HR color=red size="10" >
Form #2:
<FORM>
<INPUT TYPE="radio" NAME="choice" VALUE="three"
CHECKED> Yes.
<INPUT TYPE="radio" NAME="choice" VALUE="four"> No.
</FORM>
</BODY></HTML>
96
Output
97
Push Button
Push Button: This element would be used with
JavaScript to cause an action to take place.
<INPUT TYPE=“BUTTON”>
Browser will display
98
<DIV align=center><BR><BR>
<FORM>
<FONT Color=red>
<h1>Press Here to see a baby crying:<BR>
<INPUT TYPE="button" VALUE="PressMe"><BR><BR>
<FONT Color=blue>
Click Here to see a baby shouting:<BR>
<INPUT TYPE="button" VALUE="ClickMe" > <BR><BR>
<FONT Color=green>
Hit Here to see a baby eating:<BR>
<INPUT TYPE="button" VALUE="HitME" > <BR><BR>
<FONT Color=yellow>
</FORM></DIV>
99
100
Submit Button
Submit: Every set of Form tags requires a Submit button.
This is the element causes the browser to send the names
and values of the other elements to the CGI Application
specified by the ACTION attribute of the FORM element.
<INPUT TYPE=“SUBMIT”>
The browser will display
Submit has the following attributes:
TYPE: submit.
NAME: value used by the CGI script for processing.
VALUE: determines the text label on the button, usually
Submit Query.
101
<FORM Action="URL" method="get">
First Name: <INPUT TYPE="TEXT" Size=25
name="firstName"><BR>
Family Name: <INPUT TYPE="TEXT" Size=25
name="LastName"><BR>
<BR>
<FONT Color=red>
Press Here to submit the data:<BR>
<INPUT TYPE="submit" VALUE="SubmitData " >
</FORM>
102
103
Reset Button
• Reset: It is a good idea to include one of these for
each form where users are entering data. It allows
the surfer to clear all the input in the form.
• <INPUT TYPE=“RESET”>
104
<FORM Action="URL" method="get">
First Name: <INPUT TYPE="TEXT" Size=25
name="firstName"> <BR>
Family Name: <INPUT TYPE="TEXT" Size=25
name="LastName"><BR>
<BR>
<FONT Color = red>
<STRONG><font size=5>Press Here to submit the
data:</font></STRONG><BR>
<INPUT TYPE="submit" VALUE="SubmitData">
<INPUT TYPE="RESET" VALUE="Reset">
</FORM>
105
Image Submit Button
Image Submit Button: Allows you to substitute an
image for the standard submit button.
106
File
• File Upload: You can use a file upload to allow surfers to
upload files to your web server.
• <INPUT TYPE=“FILE”>
• Browser will display
107
<BODY bgcolor=lightblue>
<form>
<H3><font color=forestgreen>
Please attach your file here to for uploading to
My <font color =red>SERVER...<BR>
108
Other Elements used in Forms
109
<BODY bgcolor=lightblue>
<form>
<TEXTAREA COLS=40 ROWS=20 Name="comments" >
</TEXTAREA>:
</form>
</BODY>
110
Other Elements used in Forms
The two following examples are
<SELECT></SELECT> elements, where the
attributes are set differently.
The Select elements attributes are:
NAME: is the name of the variable to be sent to
the CGI application.
SIZE: this sets the number of visible choices.
MULTIPLE: the presence of this attribute signifies
that the user can make multiple selections. By
default only one selection is allowed.
111
<BODY bgcolor=lightblue>
<form>
Select the cities you have visited:
<SELECT name=“list” size=5>
<option> London</option>
<option> Tokyo</option>
<option> Paris</option>
<option> New York</option>
<option> LA</option>
<option> KL</option>
</SELECT>
</form>
</BODY>
112
Other Elements used in Forms
Option
The list items are added to the <SELECT> element
by inserting <OPTION></OPTION> elements.
The Option Element’s attributes are:
SELECTED: When this attribute is present, the
option is selected when the document is initially
loaded. It is an error for more than one option
to be selected.
VALUE: Specifies the value the variable named in
the select element.
113
<HEAD> <TITLE>SELECT with Mutiple </TITLE> </HEAD>
<BODY>
<h2><font color=blue>What type of Computer do you
have?</font><h2>
<FORM>
<SELECT NAME="ComputerType" size=5 multiple>
<OPTION value="IBM" > IBM</OPTION>
<OPTION value="INTEL"> INTEL</OPTION>
<OPTION value=" Apple"> Apple</OPTION>
<OPTION value="Compaq" SELECTED> Compaq</OPTION>
<OPTION value=" other"> Other</OPTION>
</SELECT>
</FORM></BODY></HTML>
114
115
116
Fieldset & legend
The <fieldset> tag is used to group related
elements in a form.
The <fieldset> tag draws a box around the related
elements.
The <legend> tag defines a caption for the
<fieldset> element.
117
EXAMPLE
<form>
<fieldset>
<legend>User Details:</legend>
First Name: <input type="text" size="30"><br>
Last Name: <input type="text" size="30"><br>
Password: <input type="text" size="10">
</fieldset>
</form>
118
Div tag & span tag
The HTML <div> tag is used for defining a section
of your document. With the div tag, you can
group large sections of HTML elements together
and format them with CSS.
119
Example
<html>
<head>
<title>HTML div Tag</title>
</head>
<body>
<div id="contentinfo">
<p>Welcome to our website. We provide tutorials on various
subjects.</p>
<pre>hello how r u?</pre>
</div>
</body>
120
</html>