Forms,CSS
The id and class Selectors
In addition to setting a style for a HTML element, CSS allows
you to specify your own selectors called "id" and "class".
The id Selector
The id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is defined with a "#".
The style rule below will be applied to the element with id="para1":
Example
#para1
{
text-align:center;
color:red;
}
The class Selector
The class selector is used to specify a style for a group of elements. Unlike
the id selector, the class selector is most often used on several elements.
This allows you to set a particular style for any HTML elements with the
same class.
The class selector uses the HTML class attribute, and is defined with a "."
In the example below, all HTML elements with class="center" will be
center-aligned:
Example
.center
{
text-align:center;
}
In the example below, all p elements with class="center" will be center-
aligned:
Example
p.center {text-align:center;}
body
{
background-image:url('img_tree.png');
background-repeat:no-repeat;
background-position:top right;
}
in short it can be written as:
body {background:#ffffff url('img_tree.png') no-
repeat top right;}
body {color:blue;}
h1 {color:#00ff00;}
h2 {color:rgb(255,0,0);}
h1 {text-align:center;}
p.date {text-align:right;}
p.main {text-align:justify;}
a{
text-decoration:none;
}
p.uppercase {text-transform:uppercase;}
p.lowercase {text-transform:lowercase;}
p.capitalize {text-transform:capitalize;}
p{
text-indent:50px;}
Font Family
The font family of a text is set with the font-
family property.
The font-family property should hold several
font names as a "fallback" system. If the
browser does not support the first font, it
tries the next font.
p{font-family:"Times New Roman", Times,
serif;}
p.normal {font-style:normal;}
p.italic {font-style:italic;}
p.oblique {font-style:oblique;}
h1 {font-size:40px;}
h2 {font-size:30px;}
p {font-size:14px;}
Set Font Size With Em
To avoid the resizing problem with Internet
Explorer, many developers use em instead of
pixels.
The em size unit is recommended by the W3C.
1em is equal to the current font size. The default
text size in browsers is 16px. So, the default size
of 1em is 16px.
The size can be calculated from pixels to em
using this formula: pixels/16=em
Example
h1 {font-size:2.5em;} /* 40px/16=2.5em */
h2 {font-size:1.875em;} /* 30px/16=1.875em */
p {font-size:0.875em;} /* 14px/16=0.875em */
td
{
• table, th, td height:50px;
{ vertical-align:bottom;
border: 1px solid }
black;
td
}
{
padding:15px;
• }
table,th, td table, td, th
{ {
border: 1px solid border:1px solid green;
black;
}
}
th
{
background-color:green;
color:white;
}
Forms
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.
1. Create a FORM.
2.
2. Add elements to a FORM.
3.
3. Define CGI (Common Gateway Interface).
The common gateway interface (CGI) is a standard way for a
Web server to pass a Web user's request to an application
program and to receive data back to forward to the user. This
method or convention for passing data back and forth
between the server and the application is called the common
gateway interface (CGI).
4.
4. Describe the purpose of a CGI Application.
5.
5. Specify an action for the FORM.
Forms work in all browsers.
Forms are Platform Independent.
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.example.com/formtest.php”>
<P> First Name: <INPUT TYPE=“TEXT” NAME=“fname”
MAXLENGTH=“50”> </P>
<P> <INPUT TYPE=“SUBMIT” NAME=“fsubmit1” VALUE=“Send Info”>
</P>
</FORM>
</BODY> </HTML>
<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. The CGI application
should be written to accept the data from either
method.
NAME: is a form name used by VBScript or
JavaScripts.
TARGET: is the target frame where the response
page will show up.
12
Form Elements
Form elements have properties: Text
boxes, Password boxes, Checkboxes,
Option(Radio) buttons, Submit, Reset,
File, Hidden and Image.
The properties are specified in the TYPE
Attribute of the HTML element
<INPUT></INPUT>.
Sami Ali
Al al-Bayt University
Form Elements
<INPUT> Element’s Properties
TYPE= Type of INPUT entry field.
NAME = Variable name passed to CGI application
VALUE= The data associated with the variable
name to be passed to the CGI application
CHECKED= Button/box checked
SIZE= Number of visible characters in text field
MAXLENGHT= Maximum number of characters
accepted.
Text Box
Text boxes : Used to provide input fields for text, phone
numbers, dates, etc.
<INPUT TYPE= " TEXT " >
Browser will display
Textboxes use the following attributes:
TYPE: text.
SIZE: determines the size of the textbox in characters.
Default=20 characters.
MAXLENGHT : determines the maximum number of
characters that the field will accept.
NAME: is the name of the variable to be sent to the CGI
application.
VALUE: will display its contents as the default value.
Example on Text Box
<TITLE>Form_Text_Type</TITLE>
</HEAD> <BODY>
<h1> <font color=blue>Please enter the following
bioData</font></h1>
<FORM name="fome1" Method= " POST " Action= " URL " >
First Name: <INPUT TYPE="TEXT" NAME="FName"
SIZE="15" MAXLENGTH="25"><BR>
Last Name: <INPUT TYPE="TEXT" NAME="LName"
SIZE="15" MAXLENGTH="25"><BR>
Nationality: <INPUT TYPE="TEXT" NAME="Country"
SIZE="25" MAXLENGTH="25"><BR>
The Phone Number: <INPUT TYPE="TEXT" NAME="Phone"
SIZE="15" MAXLENGTH="12"><BR>
</FORM> </BODY> </HTML>
Output
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.
19
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=“actionform.php"
method=“POST">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>
20
Output
21
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.
Check Box
Check Box : Check boxes allow the users to select more
than one option.
<INPUT TYPE=“CHECKBOX”>
Browser will display
Checkboxes have the following attributes:
TYPE: checkbox.
CHECKED: is blank or CHECKED as the initial
status.
NAME : is the name of the variable to be sent to the
CGI application.
VALUE: is usually set to a value.
<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"> 24
Output
Radio Button
Radio Button: Radio buttons allow the users to select
only one option.
<INPUT TYPE=“RADIO”>
Browser will display
Radio buttons have the following attributes:
TYPE: radio.
CHECKED: is blank or CHECKED as the initial status. Only one
radio button can be checked
NAME: is the name of the variable to be sent to the CGI
application.
VALUE: usually has a set value.
<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>
<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>
Push Button
Push Button: This element would be used with
JavaScript to cause an action to take place.
<INPUT TYPE=“BUTTON”>
Browser will display
Push Button has the following attributes:
TYPE: button.
NAME: is the name of the button to be used in scripting.
VALUE: determines the text label on the button.
<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>
31
32
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.
33
<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>
35
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”>
Browser will display
Reset buttons have the following attributes:
TYPE: reset.
VALUE: determines the text label on the button,
usually Reset.
36
<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>
38
Image Submit Button
Image Submit Button: Allows you to substitute an
image for the standard submit button.
<INPUT TYPE=“IMAGE” SRC=“jordan.gif”>
Image submit button has the following attributes:
TYPE: Image.
NAME: is the name of the button to be used in scripting.
SRC: URL of the Image file.
39
<form>
<H1><font color=blue>
Click to go Jordan’s Map:
<INPUT TYPE="IMAGE" SRC="jordan.gif">
</form>
40
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
File Upload has the following attributes:
TYPE: file.
SIZE: is the size of the text box in characters.
NAME: is the name of the variable to be sent to the
CGI application.
MAXLENGHT: is the maximum size of the input in the
textbox in characters.
41
<BODY bgcolor=lightblue>
<form>
<H3><font color=forestgreen>
Please attach your file here to for uploading to
My <font color =red>SERVER...<BR>
<INPUT TYPE="File" name="myFile"
size="30">
<INPUT TYPE="Submit" value="SubmitFile">
</form>
</BODY>
Other Elements used in Forms
<TEXTAREA></TEXTAREA>: is an element that
allows for free form text entry.
Browser will display
Textarea has the following attributes:
NAME: is the name of the variable to be sent to
the CGI application.
ROWS: the number of rows to the textbox.
COLS: the number of columns to the textbox.
43
<BODY bgcolor=lightblue>
<form>
<TEXTAREA COLS=40 ROWS=20
Name="comments" >
From observing the apathy of those
about me during flag raising I
concluded that patriotism if not
actually on the decline is at least
in a state of dormancy.
Written by Khaled Al-Fagih
</TEXTAREA>:
</form>
</BODY>
45
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.
46
<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>
47
48
Other Elements used in Forms
Drop Down List:
Name: is the name of the variable to be sent to
the CGI application.
Size: 1.
49
Other Elements used in Forms
List Box:
Name: is the name of the variable to be sent
to the CGI application.
SIZE: is greater than one.
50
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.
51
</HEAD>
<BODY>
<h2><font color=blue>What type of Computer do you
have?</font><h2>
<FORM>
<SELECT NAME="ComputerType" size=4>
<OPTION value="IBM" SELECTED> IBM</OPTION>
<OPTION value="INTEL"> INTEL</OPTION>
<OPTION value=" Apple"> Apple</OPTION>
<OPTION value="Compaq"> Compaq</OPTION>
</SELECT>
</FORM></BODY></HTML>
52
53
<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> 54
55
56