HTML Forms
HTML Forms
1
Introduction to Hypertext
HTML: Hypertext Markup Language
Hypertext …
links within and among Web documents
connect one document to another
Origins of HTML
HTML is based on SGML (Standardized
General Markup Language)
Tim Berners-Lee created first
HTML version in the late 1980s (as a
subset of SGML).
What is HTML?
• HTML (Hypertext Markup Language)
• HTML standards are developed under the authority of the World
Wide Web Consortium (W3C), headed by Tim Lee
• http://www.w3c.org
• HTML is the set of "markup" symbols or codes inserted in a file
intended for display on a World Wide Web browser.
• The markup tells the Web browser how to display a Web page's text,
images, sound and video files for the user.
• The individual markup codes are referred to as elements (but many
people also refer to them as tags).
HTML Documents
<HEAD>
<TITLE> My web page </TITLE>
</HEAD>
<BODY>
Content of the document
</BODY>
</HTML>
HTML Tags
Fruit
<UL> Fruit
<LI> Banana • Banana
<LI>Grape •Grape
</UL>
Ordered list:
Numbered list:
Fruit
<OL> Fruit
<LI> Banana 1. Banana
<LI>Grape 2. Grape
</OL>
You have the choice of setting the TYPE Attribute to one of
five numbering styles
47
Example
<table border=1 cellpadding =2>
<tr>
<th> Column 1 Header</th>
<th> Column 2 Header</th>
</tr> <tr>
<td colspan=2> Row 1 Col 1</td>
</tr> <tr>
<td rowspan=2>Row 2 Col 1</td>
<td> Row 2 Col2</td>
</tr> <tr>
<td> Row 3 Col2</td>
</tr> </table>
Output
Row 1 Col 1
Row 2 Col 2
Row 2 Col 1
Row 3 Col 2
49
Row –column format
Tables
52
Images
<img src= "logoblue.gif" width="153" height="31"
border="0”>
Image Attributes
Image File (SRC:source): This value will be a URL (location of the image) E.g.
http://www.domain.com/dir/file.ext or /dir/file.ext.
Alignment (ALIGN): This allows you to align the image on your page.
Width (WIDTH): is the width of the image in pixels.
Height (HEIGHT): is the height of the image in pixels.
Border (BORDER): is for a border around the image, specified in pixels.
HSPACE: is for Horizontal Space on both sides of the image specified in pixels. A setting
of 5 will put 5 pixels of invisible space on both sides of the image.
VSPACE: is for Vertical Space on top and bottom of the image specified in pixels. A
setting of 5 will put 5 pixels of invisible space above and bellow the image.
Example: Adding Image
Doc1.html Doc2.html
Frames.html
• A frameset partitions a web browser window
so that multiple web documents can be
displayed simultaneously.
• Example application: To maintain a
permanently visible directory of links within
your site, while also displaying one or more
selected documents from the site.
– otherwise the directory of links must appear on every page,
and this scrolls up with the page
Creating frames
A <FRAMESET> element is placed in the html document before
the <BODY> element. The <FRAMESET> describes the amount of
screen real estate given to each windowpane by dividing the screen
into ROWS or COLS.
</HTML>
Attributes for <FRAMESET>
ROWS : Determines the size and number of rectangular rows within a
<FRAMESET>.
COLS: Determines the size and number of rectangular columns within a
<FRAMESET>,
FRAMEBORDER : Possible values 0, 1, YES, NO. A setting of zero will
create a borderless frame.
FRAMESPACING: This attribute is specified in pixels. If you go to
borderless frames you will need to set this value to zero as well, or you will
have a gap between your frames where the border used to be.
BORDER(thickness of the Frame): This attribute specified in pixels. A
setting of zero will create a borderless frame. Default value is 5.
BORDERCOLOR: This attribute is allows you choose a color for your
border. This attribute is rarely used.
Attributes for <FRAME>
<FRAME>: This element defines a single frame within a frameset. There will
be a FRAME element for each division created by the FRAMESET element.
This tag has the following attributes:
SRC: Required, as it provides the URL for the page that will be displayed in
the frame.
NAME: Required for frames that will allow targeting by other HTML
documents. Works in conjunction with the target attribute of the <A>,
<AREA>, <BASE>, and <FORM> tags.
MARGINWIDTH: Optional attribute stated in pixels. Determines
horizontal space between the <FRAME> contents and the frame’s borders.
MARGINHEIGHT: Optional attribute stated in pixels. Determines vertical
space between the <FRAME> contents and the frame’s borders.
SCROLLING: Displays a scroll bar(s) in the frame. Possible values are:
1. Yes – always display scroll bar(s).
2. No – never display scroll bar(s).
3. Auto – browser will decide based on frame contents.
By default: scrolling is auto.
What will be the output?
<HEAD>
<FRAMESET ROWS="25%,50%,25%”
<FRAME SRC="">
<FRAMESET COLS="25%,*">
<FRAME SRC="">
<FRAME SRC="">
</FRAMESET>
<FRAME SRC="">
</FRAMESET>
</HEAD>
Frame Formatting
Example:
66
67
navigation.html
The anchor tag has a target attribute
– takes the name of the frame used to display the information
All anchors below are targeted to the "mainF" frame
<html><head><title>Navigation Bar</title></head>
<body><center>
<a href="course.html" target="mainF">HTML Course</a><br><br>
<a href="paragraph.html" target="mainF">Paragraphs</a><br>
<a href="headings.html" target="mainF">Headings</a><br>
<a href="ulists.html" target="mainF">Unordered lists</a><br>
<a href="olists.html" target="mainF">Ordered lists</a><br>
<a href="nlists.html" target="mainF">Nested lists</a><br>
<a href="intro.html" target="mainF">Home</a><br>
</center></body>
</html>
Nested framesets
<html>
<head><title>Frames 2</title></head>
<frameset cols="140,*">
<frame name="navF" src="navigation.html">
<frameset rows="30%,70%">
<frame name="upperF" src="intro.html">
<frame name="lowerF" src="course.html">
</frameset>
</frameset>
</html>
Forms
• Forms are user interfaces for data input
• Main application: to provide user input for
– programs and databases located on a web server
– local (client-side) scripts associated with the form
• Server-based programs may return data to the
client as a web page
• Client-side scripts can read input data
– To validate the data, prior to sending to server
– To use in local processing which may output web page
content that is displayed on the client
<FORM> Attributes
ACTION: is the URL of the 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 any scripting language
TARGET: is the target frame where the response page will show up.
72
Example applications
• Questionnaires to provide feedback on a web
site
• e-commerce, to enter name, address, details of
purchase and credit-card number
– request brochures from a company
– make a booking for holiday, cinema etc.
– buy a book, cd, etc
– obtain a map giving directions to a shop
• Run a database query and receive results (an
important part of e-commerce)
Input types
• text
• checkbox
• radio (buttons)
• select (options)
• textarea
• password
• button
• submit
• reset
• hidden
• file
• image
The method and action attributes
• The method attribute specifies the way that form data is sent to the
server program
– GET appends the data to the URL
– POST sends the data separately
• The action attribute specifies a server program (e.g. a php
program .php extension) that processes the form data
• Can also send an email: action=“mailto:[email protected]”
<body>
<form method="POST" action="comments.pl">
<h2>Tell us what you think</h2>
<!-- etc -->
</form>
</body>
The input element: type="text"
• The type attribute specifies the type of
user input
• The name attribute gives an identifier to
the input data
• The size attribute specifies the length
of the input field
• The value attribute specifies an initial
value for the text (optional)
86
Write HTML for the following…
<h2>Sign Up!</h2>
<form action="mailto:[email protected]" enctype="text/plain" method="post">
<label>Name: <input name="name" type="text"></label>
<br>
<label>Email: <input name="email" type=“text"></label>
<br>
<label>Location:
<select name="location">
<option value="syd">Sydney</option>
<option value="nyc">New York</option>
</select></label>
<br>
<label>Gender:
<input type="radio" name="gender">Female
<input type="radio" name="gender">Male
</label>
<br>
<label>Experience:
<br>
<textarea name="experience"></textarea>
</label>
<br>
<button type="submit">Sign Up</button>
</form>