Chapter 3 - Table & Forms
Chapter 3 - Table & Forms
Forms
Chapter 3
Objectives
1 Introducing Tables
2 Styling Tables
3 Introducing Forms
4 Form Control
Elements
Section 1 of 6
Introducing Tables
HTML Tables
▪ A grid of cells
1. Table Row<TR></TR>.
2. Table Header <TH></TH>.
3. Table Data <TD></TD>.
4. Caption <CAPTION></CAPTION>.
The table row elements usually contain table header elements or table data
elements.
Tables Basics
▪ Rows and cells
– <table>
<tr>
<td>The Death of Marat</td>
</tr>
content
– </table>
A basic Example
Tables Attributes
▪ BG Color: Some browsers support background colors in a
table.
▪ Width: you can specify the table width as an absolute number
of pixels or a percentage of the document width. You can set
the width for the table cells as well.
▪ Border: You can choose a numerical value for the border
width, which specifies the border in pixels.
▪ Cell Spacing: Cell Spacing represents the space between cells
and is specified in pixels.
Table Attributes
▪ Cellpadding: Cell Padding is the space between the
cell border and the cell contents and is specified in
pixels.
▪ Align: tables can have left, right, or center
alignment.
▪ Background: Background Image, will be titled in
IE3.0 and above.
▪ Border Color, Border Color Dark.
10
Table Border & Header Attribute
❑ To display a table with borders, you will use the border attribute.
11
Table Caption
▪ A table caption allows you to specify a line of text that will
appear centered above or bellow the table.
12
Source Output
<table border="1">
<caption>This is a
caption</caption>
<thead> <tr><td>head
1</td> <td>head 2</td> </tr>
</thead>
<tbody>
<tr><td>Cell 1</td> <td>Cell
2</td> </tr>
</tbody>
<tfoot> <tr><td>Sum1</td>
<td>Sum2</td> </tr>
</tfoot>
</table>
Table Data and Table Header Attributes
▪ Colspan: Specifies how many cell columns of the table this cell should
span.
▪ Rowspan: Specifies how many cell rows of the table this cell should
span.
A B C
D E F
Cell Padding and Spacing :
Cell spacing tag is used to create space between different cells within your table.
A B C
D E F
Rowspan & Colspan attribute
colspan attribute use to merge two or more columns into a single column.
rowspan use to merge two or more rows.
ROWSPAN COLSPAN
<TABLE BORDER> <TABLE BORDER>
<TR> <TR>
<TD>Item 1</TD> <TD>Item 1</TD>
<TD ROWSPAN=2>Item 2</TD> <TD COLSPAN=2>Item 2</TD>
<TD>Item 3</TD> </TR>
</TR> <TR>
<TR> <TD>Item 3</TD> <TD>Item 4</TD>
<TD>Item 4</TD> <TD>Item 5</TD> <TD>Item 5</TD>
</TR> </TR>
</TABLE> </TABLE>
– You can also set border color also using bordercolor attribute.
<HTML> Tables Backgrounds :
<HEAD>
<TITLE>HTML Table Background </TITLE>
/<HEAD>
<BODY>
< table border=">"wolley"=rolocgb "neerg"=rolocredrob "1
< tr>
< th>column >ht/<1
< th>column >ht/<2
< th>column >ht/<3
/< tr>
< tr><td rowspan="1 woR>"2cell 1 wor>dt<>dt/<1cell 1 wor>dt<>dt/<2cell
>rt/<>dt/<3
< tr><td>Row 2 cell 2 wor>dt<>dt/<2cell >rt/<>dt/<3
< tr><td>colspan="3 wor>"3cell >rt/<>dt/<1
/< table>
/< BODY>
/<HTML>
Tables: Background Image
Table Size :
Table Width & Height:
▪ You can specify table width or height in terms of pixels or in terms of percentage of
available screen area. It can be defined as a fixed width or a relative width.
▪ A fixed table width is one where the width of the table is specified in pixels.
▪ For example, this code, <table width="550" height="150">, will produce a table that
is 550 pixels wide.
▪ Hence this code, <table width="80%">, will produce a table that occupies 80
percent of the screen.
Source Output
colgroup that has three columns of
different widths:
<tbody>
<colgroup span="3“
style=“color:#FF0000”<
<col width="20"></col>
<col width="50"></col>
<col width="80"></col>
</colgroup>
<tr> <td>1</td> <td>2</td>
<td>3</td> <td>4</td>
</tr>
</tbody>
HTML Tables
Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td (row,col)span> Defines a table cell (table data)
<caption> Defines a table caption
<colgroup> Defines groups of table columns
Defines the attribute values for
<col>
one or more columns in a table
<thead> Defines a table head
<tbody> Defines a table body
<tfoot> Defines a table footer
Attribute Value Description
align left Aligns the table. Deprecated.
center Use styles instead.
right
bgcolor rgb(x,x,x) Specifies the background color of
#xxxxxx the table.
colorname
border pixels Specifies the border width.
Tip: Set border="0" to display tables with
no borders!
cellpadding pixels Specifies the space between the
% cell walls and contents
cellspacing pixels Specifies the space between cells
%
width % Specifies the width of the table
pixels
Basic Table Code
<TABLE BORDER=1 width=50%>
<CAPTION> <h1>Spare Parts <h1> </Caption>
<TR><TH>Stock Number</TH><TH>Description</TH><TH>List Price</TH></TR>
<TR><TD bgcolor=red>3476-AB</TD><TD>76mm Socket</TD><TD>45.00</TD></TR>
<TR><TD >3478-AB</TD><TD><font color=blue>78mm Socket</font>
</TD><TD>47.50</TD></TR>
<TR><TD>3480-AB</TD><TD>80mm Socket</TD><TD>50.00</TD></TR>
</TABLE>
26
Special Things to Note
▪ TH, TD and TR should always have end tags.
Although the end tags are formally optional, many browsers will mess up
the formatting of the table if you omit the end tags. In particular, you
should always use end tags if you have a TABLE within a TABLE -- in this
situation, the table parser gets hopelessly confused if you don't close your
TH, TD and TR elements
27
What will be the output?
>TABLE BORDER width=“750”<
<TR> <TD colspan=“4” align=“center”<Page Banner>/TD<>/TR<
28
The Output
29
▪ Section 3 of 6
Introducing Forms
HTML Forms
▪ Richer way to interact with server
Example:
<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>
34
<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.
▪ TARGET: is the target frame where the response page will show up.
35
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>.
36
Sami Ali
Al al-Bayt University
38
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.
39
Text Box
▪ Text boxes: Used to provide input fields for text, phone numbers, dates, etc.
<input type=“text” name=“firstName”>
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.
40
Text Box Example
<form action="http://www.example.com/login.php">
<p>Username:<input type="text" name="username" size="15“ maxlength="30" /></p>
</form>
Example on Text Box
<TITLE>Form_Text_Type</TITLE>
</HEAD> <BODY>
<FORM name="fome1" Method= " get " Action= " URL " >
42
Output
43
Password Box
▪ Password: Used to allow entry of passwords.
<input type=“password” name=“password”>
44
Example on Password Box
<form action="http://www.example.com/login.php">
<p>Username:
<input type="text" name="username" size="15"
maxlength="30" />
</p>
<p>Password:
<input type="password" name="password" size="15"
maxlength="30" />
</p>
</form>
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>
46
Output
47
TEXT AREA
▪ <TEXTAREA></TEXTAREA>: is an element that allows for free
form text entry.
<input type=“text” name=“firstName”>
48
TEXT AREA Example
<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
Out put
</TEXTAREA>:
From observing the apathy of those
</form>
about me during flag raising I
</BODY> concluded that patriotism if not
actually on the decline is at least
in a state of dormancy.
Written by Khaled Al-Fagih
49
Check Box
▪ Check Box: Check boxes allow the users to select more than one option.
<input type=“checkbox” name=“sauce” value=“yes”>
Browser will display
▪ TYPE: checkbox.
50
Checkboxes
Example:
<input type="checkbox" name="sauce" value="yes" checked> Sauce<br>
However, if you click on the word, you cannot select the checkbox
<HTML>
Check Box Example
<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>
52
Output
53
Radio Button
▪ Radio Button: Radio buttons allow the users to select only one option.
<input type=“radio” name=“gender” value=“male”>
54
Radio Button Example
Often, we want to display radio buttons or checkbox groups together We can
do this with the field set element
<fieldset>
<legend>Gender</legend>
<input type="radio" name="gender" value=“male" id=“male">
<input type="radio" name="gender" value="female" id=“female">
</fieldset><br>
<HTML> Radio Button Example
<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> 56
57
Radio Button Example
<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>
58
Output
59
Push Button اضغط الزر
▪ Push Button: This element would be used with JavaScript to cause
an action to take place.
سيتم استخدام هذا العنصر مع جافا سكريبت ليؤدي إلى اتخاذ إجراء
<INPUT TYPE=“BUTTON”>
Browser will display
▪ TYPE: button.
60
Push Button Example
<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>
61
62
Submit and Reset إرسال وإعادة تعيين
The reset button allows the user to clear out any user input and reset the field
to the default values assigned for each field.
يسمح للمستخدم بمسح أي إدخال للمستخدم وإعادة تعيين الحقل إلى القيم االفتراضية المعينة لكل حقل
Attribute:
The attribute value can be utilized to change the text that appears on the
button
Submit and Reset
Example:
<input type=“submit”><input type=“reset”>
65
66
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”>
67
Reset Button Example
<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>
68
69
Image Submit Button
▪ Image Submit Button: Allows you to substitute an image for the
standard submit button.
70
<form>
<H1><font color=blue>
Click to go Jordan’s Map:
<INPUT TYPE="IMAGE" SRC=“Saudi arabia.gif">
</form>
71
File Input Box
▪ File Upload: You can use a file upload to allow surfers to upload files to
your web server.
<INPUT TYPE=“FILE”>
Browser will display
72
File Input Box Example
<form action="http://www.example.com/upload.php"
method="post">
<p>Upload your song in MP3 format:</p>
<input type="file" name="user-song" /><br />
<input type="submit" value="Upload" />
</form>
File Input Box Example
<BODY bgcolor=lightblue>
<form>
<H3><font color=forestgreen>
</form>
</BODY>
74
Select Box
▪ The two following examples are <SELECT></SELECT> elements,
where the attributes are set differently.
75
<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>
76
Drop Down List
▪ Drop Down List:
▪ Name: is the name of the variable to be sent to the CGI application.
▪ Size: 1.
<form
action="http://www.example.com/profile.php">
<p>What device do you listen to music on?</p>
<select name="devices">
<option value="ipod">iPod</option>
<option value="radio">Radio</option>
<option value="computer">Computer</option>
</select>
</form>
77
List Box
▪ List Box:
78
Option
▪ Option
The list items are added to the <SELECT> element by inserting
<OPTION></OPTION> elements.
79
Option Example
</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>
80
81
Option Example
<HTML>
<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>
82
83
Grouping Form Elements
<fieldset>
<legend>Contact details</legend>
<label>Email:<br />
<input type="text" name="email" /></label><br />
<label>Mobile:<br />
<input type="text" name="mobile" /></label><br />
<label>Telephone:<br />
<input type="text" name="telephone" /></label>
</fieldset>
Date Input تاريخ اإلدخال type="date"
date Creates a general date input control. The format for the date is "yyyy-mm-dd".
time Creates a time input control. The format for the time is "HH:MM:SS", for
hours:minutes:seconds.
datetime Creates a control in which the user can enter a date and time.
datetime-local Creates a control in which the user can enter a date and time without specifying a time zone.
month Creates a control in which the user can enter a month in a year. The format is "yyyy-mm".
week Creates a control in which the user can specify a week in a year. The format is "yyyy-W##".
Email & URL Input type="email"
<form action="http://www.example.org/subscribe.php">
<p>Please enter your email address:</p>
<input type="email" name="email" />
<input type="submit" value="Submit" />
</form>
90
Form-Related HTML Elements
Type Description
<datalist> An HTML5 element form defines lists to be used with other form elements.
<input> Defines an input field. HTML5 defines over 20 different types of input.
textarea Creates a multiline text entry box. <textarea rows="3" ... />
password Creates a single line text entry box for a password <input type="password" ... />
search Creates a single-line text entry box suitable for a search string. This is an HTML5 element.
email Creates a single-line text entry box suitable for entering an email address. This is an HTML5 element.
tel Creates a single-line text entry box suitable for entering a telephone. This is an HTML5 element.
url Creates a single-line text entry box suitable for entering a URL. This is an HTML5 element.
<input type="reset"> Creates a button that clears any of the user’s already
entered form data.
<input type="image"> Creates a custom submit button that uses an image for its
display.
1 Introducing Tables
2 Styling Tables
3 Introducing Forms
4 Form Control
Elements
<form method=”post” action=”ex10.php”>
First Name: <input type=”text”
name=”fname”><br>
Last Name: <input type=”text” name=”lname”><p>
<input type=”submit” value=”Click here”>
<input type=”reset” value=”Clear All”>
</form>