It3401 - We Course File
It3401 - We Course File
REGULATION 2021
IT3401
WEB ESSENTIALS
COURSE FILE
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
1. TIME TABLE
2. SYLLABUS
3. LESSON PLAN
4. COURSE MATERIAL
7. ANSWER KEY - 1
9. ANSWER KEY -2
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
TIME TABLE
Ms. D.Sujatha
1 2 3 4 5 6 7
Days /
Hours 10.35- 03.05-
08.30-09.30 09.30-10.25 11.30-12.25 01.15-02.10 02.10-03.05
11.30 04.00
IT3401
TUE
WE
WED
IT3401
THU
WE
IT3401 IT3401
FRI
WE WE
SAT
SYLLABUS
3024
COURSE OBJECTIVES:
To comprehend and analyze the basic concepts of web programming and internet protocols.
Internet Overview - Fundamental computer network concepts - Web Protocols - URL – Domain Name-
Web Browsers and Web Servers- Working principle of a Website –Creating a Website - Client-side and
server-side scripting
HTML – Form Elements - Input types and Media elements - CSS3 - Selectors, Box Model, Backgrounds
and Borders, Text Effects, Animations, Multiple Column Layout, User Interface.
PHP - Working principle of PHP - PHP Variables - Constants - Operators – Flow Control and Looping -
Arrays - Strings - Functions - File Handling - File Uploading – Email Basics - Email with attachments -
PHP and HTML - Simple PHP scripts - Databases with PHP
Servlets: Java Servlet Architecture – Servlet Life cycle- Form GET and POST actions -Sessions – Cookies
– Database connectivity - JDBC
Creation of simple interactive applications - Simple database applications
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
PRACTICAL EXERCISES:
1. Creation of interactive web sites - Design using HTML and authoring tools
2. Form validation using JavaScript
3. Creation of simple PHP scripts
4. Handling multimedia content in web sites
5. Write programs using Servlets:
i. To invoke servlets from HTML forms
ii. Session tracking using hidden form fields and Session tracking for a hit count
6. Creation of information retrieval system using web, PHP and MySQL
7. Creation of personal Information System
COURSE OUTCOMES:
TEXT BOOKS
1. Robin Nixon, "Learning PHP, MySQL, JavaScript, CSS & HTML5" Third Edition, O'Reilly publishers,
2014.
2. Paul Deitel, Harvey Deitel, Abbey Deitel, “Internet & World Wide Web - How to Program”, 5th
edition, Pearson Education, 2012.
REFERENCES:
1. Jeffrey C. Jackson, "Web Technologies--A Computer Science Perspective", Pearson Education, 2006.
2. James F. Kurose, “Computer Networking: A Top-Down Approach”, Sixth Edition, Pearson Education,
2012
3. Steven Holzener , “PHP – The Complete Reference”, 1st Edition, Mc-Graw Hill, 2017
4. Fritz Schneider, Thomas Powell , “JavaScript – The Complete Reference”, 3rd Edition, Mc- Graw Hill
Publishers, 2017
5. Bates, “Developing Web Applications”, Wiley Publishers, 2000
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
LESSON PLAN
Unit – 1
9,10,11
OF FEB
Fundamental Computer
2 09-02-2023/2 BB T1 14-2-23/4 MONTH 1 1,5
Network Concepts
TAKEN
LEAVE
Working Principle Of A
7 16-02-2023/2 BB,PPT T1 18-2-23/3 1 3,5
Website
BB,
9 17-02-2023/6 Client-Side Scripting T1 21-2-23/4 1 2,3,5
DEMO
BB,
10 18-02-2023/3 Server-Side Scripting T1 22-2-23/1 1 2,3,5
DEMO
SLIP
11 21-02-2023/4 Revision 22-2-23/7
TEST
Unit -2
Executed Reason
For
No. POs/
Planned
Topic Pedagogy Resource Date/ COs
Date/ Period PSOs
Period Deviation
13 24-02-
24-02-2023/1 Form Element PPT,DEMO T1 2 3,5
2023/1
15 CSS3 25-02-
25-02-2023/3 BB T1 2 1,2,3
2023/3
3-3-23 -
18 03-03-2023/1 Text Effects PPT T1 4-3-23/3 TAKEN 2 1,2,3
LEAVE
Unit- 3
11-3-23 TO
25 30-03- Operators BB T1 30-3-23/6 28-3-23 3 1,2,5
2023/2
ASSESSMENT
26 31-03-
1-4-23/3 31-3-23
2023/1
Literals Functions, Object BB T1 TAKEN 3 1,2,5
27 31-03- LEAVE
6-4-23/2
2023/6
30 08-04-
Regular Expression BB R3 3 2,3,5
2023/3
31 11-04-
Exceptions BB R3 3 2,3
2023/4
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
32 13-04-
Event Handling PPT R4 3 2,3
2023/2
33 15-04- R3
JS Debuggers BB 3 2,3
2023/3
20-04-
35 Revision SLIP TEST
2023/2
Unit- 4
Executed Reason
Planned For POs/
No. Date/ Topic Pedagogy Resource COs
Date/ PSOs
Period
Period Deviation
21-04-
36
2023/1 PHP
PPT T1 4 1,2,3,4,5
21-04- Working principle of PHP
37
2023/6
38 22-04- PPT,
PHP Variables T1 4 2,3
2023/3 DEMO
25-04-
39 Constants BB T1 4 2,3,5
2023/4
40 27-04-
Operators BB T1 4 2,3,5
2023/2
25-04-
41 Flow Control and Looping BB T1 4 2,3
2023/4
28-04-
42 Arrays – Strings BB T1 4 2,3,5
2023/1
28-04-
43 Functions – File Handling PPT/BB T1 4 2,3,5
2023/6
04-05-
46 Databases with PHP DEMO T1 4 3,5
2023/2
05-05- SLIP
47 Revision
2023/1 TEST
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Unit- 5
Executed Reason
No. For POs/
Planned
Topic Pedagogy Resource COs
Date/ Period Date/ PSOs
Period Deviation
JDBC
55 23-05-2023/4
Creation of simple PPT /
T2 5 3,5
interactive application BB/DEMO
56 25-05-2023/2
List of Pedagogies: Chalk & Talk/ Quiz/ MCQs/ Flipped Class/ Demonstration/ Site Visit/ Role Play/ Video/
TEXT BOOK(S):
T1. Robin Nixon, “Learning PHP, MySQL, JavaScript, CSS & HTML5” Third Edition, O’Reilly publishers, 2014.
T2. Paul Deitel, Harvey Deitel, Abbey Deitel, “Internet & World Wide Web – How to Program”, 5th edition, Pearson
Education, 2012.
REFERENCES:
R1. Jeffrey C. Jackson, “Web Technologies–A Computer Science Perspective”, Pearson Education, 2006.
R2. James F. Kurose, “Computer Networking: A Top-Down Approach”, Sixth Edition, Pearson Education, 2012
R3. Steven Holzener , “PHP – The Complete Reference”, 1st Edition, Mc-Graw Hill, 2017
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
R4. Fritz Schneider, Thomas Powell , “JavaScript – The Complete Reference”, 3rd Edition, McGraw Hill Publishers,
2017
R5. Bates, “Developing Web Applications”, Wiley Publishers, 2006
Prerequisite Courses:
Basic knowledge in Java, HTML and Web Services
Course Objective Understand about client-server communication and protocols used during
communication.
Design interactive web pages using Scripting languages.
Learn server side programming using servlets and JSP.
Develop web pages using XML/XSLT.
The students will be able to,
CO1: Design simple web pages using HTML and XHTML.
Course Outcomes CO2: Design & develop dynamic web pages using DHTML & Java script.
CO3: Experiment with server side programming using DOM & Servlet.
CO4: Develop web applications using JSP & construct web data using XML.
CO5: Understand web services & identify the interactions among web services.
POs PSOs
COs PO- PO- PO- PO- PO- PO- PO- PO- PO- PO- PO- PO- PSO- PSO PSO
1 2 3 4 5 6 7 8 9 10 11 12 1 -2 -3
CO- 3 2 3 2 3 2 0 0 2 2 2 3 3 2 1
1
CO- 3 3 3 3 3 2 0 0 2 0 2 3 3 2 1
2
CO- 3 3 3 2 3 2 0 0 2 2 2 3 3 2 1
3
CO- 3 3 3 3 3 1 0 0 1 1 2 3 3 2 1
4
CO- 3 3 3 3 3 1 0 0 0 0 2 3 3 2 1
5
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
COURSE MATERIAL – IT3401 WEB ESSENTIALS
UNIT I
Internet Overview - Fundamental computer network concepts - Web Protocols - URL – Domain Name-
Web Browsers and Web Servers- Working principle of a Website –Creating a Website - Client-side and
server-side scripting
Introduction:
1.1Internet Overview :
Server:
The software that distributes the information and the machine where the inf rmati n and s ftware
reside is called the server.
Client:
The software that resides on the remote machine, comm nicates with the server, fetches the
information, processes it, and then displays it on the remote m chine is c lled the client.
Web server:
Software that delivers Web pages a d other documents to browsers using the HTTP protocol
Web Page:
A web page is a docum nt or source of information that is suitable for the World Wide Web and
can be accessed through a w b b ows .
Website:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
A collection of pages on the World Wide Web that are accessible from the same URL and typically
residing on the same server
URL:
Uniform Resource Locator, the unique address which identifies a resource on the Internet for
routing purposes.
The Client-Server paradigm is the most prevalent model for distributed computing protocols. It is
the basis of all distributed computing paradigms at a higher level of abstraction. It is service-oriented, and
employs a request-response protocol.
A server process, running on a server host, provides access to a service. A client process, running
on a client host, accesses the service via the server process.The interaction of the process proceeds
according to a protocol.
The primary idea of a client/server system is that you have a central repository of
information—some kind of data, often in a database—that you want to distribute on demand to so e set of
people or machines.
Web Browsers:
Web Server:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Server for Web is called Web
server: o Apache (public
domain)
o MS Internet Information Server
Protocol:
Protocols are agreed formats for tra sm tt g data between devices.
There are many protocols used by the Internet and the WWW:
TCP/IP
o HTTP
o FTP
TCP/IP
The Internet uses two main protocols (developed by Vincent Cerf and Robert Kahn) Transmission
control protocol (TCP):Controls disassembly of message into packets at the origin
Internet protocol (IP):Specifies the addressing details for each packet Each packet is labelled with
its origin and destination.
• The hypertext transfer protocol (HTTP) was developed by Tim Berners-Lee in 1991
HTTP was designed to transfer pages between machines
The client (or Web browser) makes a request for a given page and the Server is responsible for
finding it and returning it to the client
The browser connects and requests a page from the server
The server reads the page from the file system, sends it to the client and
terminates the connection.
o Send mail to the user’s computer and do not delete it from the server
o Ask whether new mail has arrived.
A user can view email message headers and the sender’s name before
downloading the entire message.
Allows users to delete and search mailboxes held on the email server.
The disadvantage of POP: You can only access messages from one PC
The disadvantage of IMAP :Since email is stored on the email server, there is a need for more and more
expensive (high speed) storage space.
1.7 World Wide Web: comprises software (Web server and browser) and data (Web sites).
1.8 HTTP:
Hypertext T ansf P otocol (HTTP) is the communication protocol used by the Internet to
transfer hype text documents.
A protocol to transfer hypertext requests and information between servers and browsers
Hypertext is text, displayed on a computer, with references (hyperlinks) to
other text that the reader can immediately follow, usually by a mouse HTTP is behind every request for a
web document or graph, every click of a hypertext link, and every submission of a form.
HTTP specifies how clients request data, and how servers respond to these requests.
The client makes a request for a given page and the server is responsible for finding it and
returning it to the client.
The browser connects and requests a page from the server.
The server reads the page from the file system and sends it to the client and then
terminates the connection
HTTP Transactions
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
1.9 HTTP Message:
HTTP message is the information transaction between the client and server.
Requests
Client to server
Responses
Server to client
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Fields
Request line or Response line
General header
Request header or Response header
Entity header
Entity body
Request Line:
Notes:
GET is the most common HTTP method; it says "give me this resource". Other
methods include POST and HEAD. Method names are always uppercase
The path is the part of the URL after the host name, also called the request
URI o The HTTP version always takes the form "HTTP/x.x", uppercase.
Request Header:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
o The HTTP version is in the same format as in the request line, "HTTP/x.x".
HTTP Method:
HTTP method is supplied in the request line and specifies the operation that the client has
requested.
Two methods that are mostly used are the GET and POST:
o GET for queries that can be safely repeated
o POST for operations that may have side effects (e.g. ordering a book from an on-line store).
It is used to retrieve information from a specified URI and is assumed to be a safe, repeatable
operation by browsers, caches and other HTTP aware components
Operations have no side effects and GET requests can be re-issued.
For example, displaying the balance of a bank account has no effect on the account and can be
safely repeated.
Most browsers will allow a user to refresh a page that resulted from a GET, with ut displaying
any kind of warning
Proxies may automatically retry GET requests if they encounter a temp rary netw rk c nnection
problem.
GET requests is that they can only supply data in the form of parameters en oded in the URI
(known as a Query String) – [downside]
Cannot be unused for uploading files or other operations that req ire arge amounts of data to be
sent to the server.
Used for operations that have side effects and c nnot be s fely repeated.
For example, transferring money from one b nk ccount to nother has side effects and should not
be repeated without explicit approval by the user.
If you try to refresh a page in I ter et Ex lorer that resulted from a POST, it displays the
following message to warn you that there may be s de effects:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The POST request message has a content body that is normally used to send
parameters and data
• The IIS server returns two status codes in its response for a POST request
o The first is 100 Continue to indicate that it has successfully received the POST request
o The second is 200 OK after the request has been processed.
Informational (1xx)
Successful (2xx)
Redirection (3xx)
o 301: moved permanently
1.12 HTTP
Features
Web Browsers :
• Mosaic - NCSA (Univ. of Illinois), in early 1993 First to se a GUI, ed to Explosion of Web use
Initially for X-Windows, under UNIX, but was ported to other platforms by ate 1993
Browsers are clients - always initiate, servers react (altho gh sometimes servers require
responses)
Most requests are for existing documents, using Hypertext Tr nsfer Protocol
(HTTP) But some requests are for program execution, with the output being
returned as a document.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Browser: A web browser is a software application for retrieving, resenting, and
traversing information resources on the World Wide Web.
Web Servers:
Monitor a communications po t on the host, accepting HTTP messages when they appear
All current Web serve s came f om either
1. The original from CERN
2. The second one, from NCSA
Web servers have t o main directories:
Document root (servable documents)
Server root (server system software)
Document root is accessed indirectly by clients
Its actual location is set by the server Configuration file
Requests are mapped to the actual location
Virtual document trees
Virtual hosts
Proxy servers
Web servers now support other Internet protocols
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
HTML – Form Elements - Input types and Media elements - CSS3 - Selectors, Box Model, Backgrounds
and Borders, Text Effects, Animations, Multiple Column Layout, User Interface.
Markup Language:
Mark-up Language is used to identify elements of a page so that a browser can render that page on
your computer screen.
Content to be displayed is ―marked up‖ or tagged to tell the browser how to display it.
A markup language is a set of characters or symbols that define a document’s logical structure or how a
document should be printed or displayed.
Hyper Text Mark-up Language, the language used to create documents on the W rld Wide Web.
HTML is a collection of styles (indicated by mark-up tags) that define the various elements of a
World Wide Web document.
HTML is based on an older language called Standard Genera ized Markup Language, or
SGML, which defines the data in a document independently of how the data will be displayed.
· HTML document can be read and displayed by m ny different browsers running on different types
of computers – platform independent!
HTML defines the structure and layout of the elements on a Web page with a variety of tags.
Each tag may have a set of attr butes that modify the a pearance or layout of the visual element
contained by the tag.
HTML is a plain-text file that can be created using a text editor like Notepad.
HTML is a p og amming language that allows you to tell the browser what you want it to display
and how you want it to be display d, in simple terms, it is a Webpage.
HTML there a e ce tain ma kers, like commands, that tell the Browser what to do, these are called
tags. By using tags you can have tables, fonts, colors, pictures, links, and almost anything you can think up,
and experimentation with tags can lead to some pretty cool WebPages.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
1.13 HTML History:
The first version of HTML was created using the Standard Generalized Mark up Language
(SGML).
In the early years of HTML, Web developers were free to define and modify HTML in whatever
ays they thought best.
Competing browsers introduced some differences in the language. The changes were called
extensions.
A group of Web developers, programmers, and authors called the World Wide Web
Consortium, or the WC3, created a set of standards or specifications that all browser manufacturers were
to follow.
The recommendations of the WC3are usually followed since a uniform approach to Web page
creation is beneficial to everyone.
Co m parison of H T M L versions:
HTML 3 HTML 4 HTML 5
<td>left </td>
</tr>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
HTML Basics:
HTML Elements
HTML Tags:
• Container Tags
o <Begin formatting>some text</End formatting>
Case insensitive
Unrecognised tags are simply ignored by browser!!
Container tags must be nested!!
As a text document, your HTML in Notepad will contain elements, such as headers, titles, paragraphs,
etc.
These elements must be denoted in your script, which is done using tags
HTML tags consist of a left angle bracket (<), a name, and a right angle bracket(>)
For example: <title>
Tags must also close. To do so, you incorporate a slash (/). A starting and ending tag would be: <title>
</title>.
Attributes:
Page content
Includes text, images, links, forms, etc.
Elements include backgrounds, link colors nd font f ces
P element forms a paragraph, blank line before and after
Text Styling
Underline style<U>…</U>
Align elements with ALIGN attributeright, left or center
Close nested tags in the reverse order from which they were opened
Emphasis (italics) style<EM>…</EM>
Strong (bold) style<STRONG>…</STRONG>
<B> and <I> tags deprecated Overstep boundary between content and presentation
Logical Styles:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
In XHTML tag names, attributes, and values are case sensitive and values must be encl sed by
double quotes.
In XHTML all elements must have both beginning and ending tags
Controls are tags and their attributes
o Tags often delimit content and specify something about how the content
o should be arranged in the document.
o XHTML editors
Filters
o Convert documents in other formats to XHTML
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Relative URL
HTML Link:
1. Absolute URL
• Absolute URL contains all the information necessary to identify files on the internet (Example: in
postal service, for sending letter to the destination it necess ry to have f ll information like, name, address,
city etc.,)
Likewise, an absolute URL contains the protocol, hostn me, filename, which are all essential to
link the web document.
Example:
http://google.com/index.html
Relative URL contains the only the folder name and filename or even just the file name.
Browser does not n d protocol addr ss or server name to identify the file in the web.
• Relative URL to f the docum nts in relation to the originating document.
Document Relative URL is used to relate the HTML document in the same folder, just providing
the name of the file (ex: Index.html).
It contains only the folder name and file name.
Server – Relative URL
Server relative URL is relative to the server root.
It contains the part of URL and relating to the host name.
This section discusses the A tag which is used to define anchors (places in a document that can be
linked to) and also to create links.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
A - (anchor or link)
The A tag lets you define anchors and links. An anchor defines a place in adocument. A link
displays a hypertext link that the user can click to display an anchor or a document.
A as anchor
An anchor identifies a place in an HTML document. To indicate that an <A> tag is being used as
an anchor, specify the NAME attribute.
Note that you can also use the ID attribute of any tag to identify that tag as an anchor, as discussed
in UNIVERSAL Attributes.
Syntax
<A
NAME="anchorName"
>.
..
</A>
Example
<A NAME=section2>
If this anchor is in a file called "nowhere.htm," you could define link that jumps to the anchor as
follows:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
A as link
A hypertext link is a piece of content that the user can click to invoke an action.
The most common actions are scrolling to a different place in the current document and opening a
new document.
A hypertext link can contain t xt and/or graphics.
To define a hype t xt link, use the <A> tag with an HREF attribute to indicate the start of the
hypertext link, and use the </A> tag to indicate the end of the link.
When the user clicks any content between the <A HREF> and </A> tags, the link is activated.
The value of the HREF attribute must be a URL.
• If you ant the link to open a new document, the value of HREF should be the URL for the
destination document.
• If you ant to scroll the current document to a particular place, the value of HREF should be the
name of the anchor to which to scroll, preceded by the # sign.
• If you ant to open another document at an anchor, give the URL for the document, followed by
#, follo ed by the name of the anchor.
If you want the destination document or anchor to open in a separate browser window, supply the
name of the window as the value of the TARGET attribute.
If the named window does not already exist, a new window opens.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The link can also do actions other than opening and scrolling documents. It can send mail
messages, point to files located on FTP servers, run any arbitrary JavaScript code, open local files, point to
a gopher server, or read news groups.
To do any of these actions, you specify an appropriate kind of URL, such as a mailto URL to
send a mail message or a news URL to read a news group.
Most browsers display hypertext links in a color different from that of the rest of the document so
that users can easily identify them.
You can also define actions that occur when the mouse cursor enters or leaves the region
containing the link by specifying onMouseOver and onMouseOut event handlers for the link.
• Additionally, you can specify an onClick event handler that determines the action to occur when
the user clicks a link.
Syntax
<A
HREF="location"
ONCLICK="clickJScode"
ONMOUSEOUT="outJScode"
ONMOUSEOVER="overJScode"
TARGET="windowName"
>
...
</A>
HREF="location" specifies a destinat on URL for the li k. The most common value here is a
document name or an anchor. To spec fy a docume t to open, provide the URL for the document, either as
an absolute or relative URL.
To scroll the current document to an anchor, give the name of the anchor preceded by the pound
To open a different document at an anchor, give the URL for the document, followed by the # sign
follo ed by the name of the anchor. For example:
HREF="products/doc1.html"
The HREF attribute can also be a URL that sends a message, points to files located on an FTP
server, runs arbitrary JavaScript code, opens local files, points to a gopher server, or reads news groups.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
ONCLICK="clickJScode" specifies JavaScript code to execute when a user clicks the link. If you supply
a value for the ONCLICK attribute, the specified action overrides the default link behavior.
ONMOUSEOUT="outJScode" specifies JavaScript code to execute when a user moves the mouse
cursor out of the link or anchor.
ONMOUSEOVER="overJScode" specifies JavaScript code to execute when a user oves the ouse
pointer over the image or link text.
TARGET="windowName" specifies a window in which to show the destination d cu ent (if the link's
action is to scroll or open a document). If the named window is not already open, a new wind w with that
name opens.
parent opens the destination document in the parent window of the one displaying the current
document.
self opens the destination document in the same window s the one in which the link was clicked.
top opens the destination document in the full body of the current window. This value can be used
to ensure that the destination document takes over the full window even if the original document was
displayed in a frame.
Example
<P>You can find all the latest news from Chennai Kavigal at
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<A HREF="http://www.ch nnaikavigal.com/index.html">Chennai Kavigal's
Home Page</A>.
HTML List:
Lists can add a lot to a WebPage, there are different types of lists and
different types of bullets or numbers that can be used.
You can have an ordered list (a, b, c, etc.) unordered lists (with bullets) or you
can have definition lists.
The DIR tag is intended to display a list of short items such as in a directory listing.
In practice, the DIR tag usually does the same thing as the UL (unordered list) tag.
To mark the individual items within the list, use the LI tag. A single list item can
contain additional paragraphs, marked with the P tag.
Syntax
<DIR>
...
</DIR>
Example
<LI>PRODUCTS
<DIR>
<LI>SHAKTHI.htm
<LI>TYPING TUTOR.htm
</DIR>
<LI>MULTIMEDIA
<DIR>
<LI>KURALAMUDHU.htm
<LI>ARIVODU VILAYADU.htm
</DIR>
<DIR>
DL - (definition list)
The DL tag encloses a definition list. A definition list contains terms, which are defined with the
DT tag, and definitions, which are defined with the DD tag. By default, Nadodi aligns
terms on the left and indents each def n t on on a ew li e. However, you can use the COMPACT attribute
to display a definition on the same line as the precedi g term, if it fits on one line.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The intent of a definition list s to d splay l sts of terms and their corresponding definitions, such as
in a glossary.
Syntax
<DL COMPACT>
...
</DL>
COMPACT compacts the definition list by placing the term defined by the DT tag on the same line as the
definition defined by the DD tag, provided the term is short enough.
<DL>
<DT>HTML
<DD>This tag marks a text file as an HTML document.
<DT>HEAD
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<DT>BODY
<DD>This tag displays the body for the HTML document.
<DT>DL
<DD>This tag displays a definition list in the HTML document.
<DT>DT
<DD>This tag displays a term in a definition list.
<DT>DD
<DD>This tag displays a definition description.
</DL>
DT - (definition term)
The DT tag specifies a term in a definition list. The DT tag must be used in a DL tag. Usually a DT
tag is followed by a DD tag that describes the term in the DT tag.
Syntax <DT>
DD – (Definition description)
The DD tag displays a definition description in definition list. The DD tag must be used
within a DL tag and usually follows immediately after DT t g th t indicates the term being defined. The
DD tag does not require a closing tag.
See DL for more details and an example.
Syntax <DD>
Used Within <DL>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The MENU tag displays a list of simple items. This tag works just like the UL tag. Use the LI tag
to designate the individual m nu it ms.
This tag is being dep cat d b cause it has become obsolete in favor of the UL tag.
Syntax
<MENU>
...
</MENU>
Example
The follo ing example creates a list of three short items:
<P>Menu Example:</P>
<MENU>
<LI> Windo s 9x
<LI> Windo s NT
1. Unordered List:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Syntax
1. <UL TYPE="CIRCLE"|"DISC"|"SQUARE">
TYPE defines the type of bullet used for each list item. The value can be one of the following:
CIRCLE specifies a hollow bullet.
DISC specifies a solid round bullet (Nadodi's default).
SQUARE specifies a square bullet.
Example
<ul type=‖disc‖>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ul type="square">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ul type="circle">
<li>Item 1</li>
<li>Item 2</li>
</ul>
Ordered List:
In an ordered list, each item has a seque t al leadi g symbol.
The browser assigns this seque ce automat cally.
<ol> tag is used to ordered the l st.
<li> tag is used to list the item.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Syntax
<OL
START="value"
TYPE="A"|"a"|"I"|"i"|"1"
>
...
</OL>
START="value" indicates the starting number for the list. The number must be a positive integer.
TYPE defines the type of numbering sequence used for each list item.
The value can be one of the following:
Example
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
<ol type="A" start="5">
<li>Item 1</li>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<li>Item 2</li>
</ol>
<ol type="i" start="10">
<li>Item 1</li>
<li>Item 2</li>
</ol>
Definition List
A definition list is a sequence of terms and description of these terms
<dl> tag is used to implement definition list.
<dt> tag is used for defining the item.
<dd> tag is used for defining the description.
LI - (list item)
The LI tag indicates an itemized element, which is s ally preceded by a bullet, a number, or a
letter. The LI tag is used inside list elements such as OL (ordered list) nd UL ( nordered list).
Syntax
<LI
TYPE="DISC"|"CIRCLE"|"SQUARE"|"A"|"a"|"I"|"i"|"1"
VALUE="number"
>
TYPE specifies the type of symbol or numbering sequence to use before each item.
DISC specifies a solid bull t.
CIRCLE specifies a hollow bull t.
· SQUARE specifi s a squa bull t.
A specifies a sequ nce of upp rcase letters.
a specifies a sequence of lowercase letters.
I specifies a sequence of uppercase Roman numerals.
i specifies a sequence of lowercase Roman numeral.
1 specifies a sequence of numbers.
The values DISC, CIRCLE, and SQUARE can be used in unordered lists, while the values A, a, I, i, and 1
can be used in ordered lists that have a numerical sequence.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
VALUE="number" indicates the starting number for an item in an ordered list. This attribute is valid
only in an ordered list. See OL for information on the types of numbering available.
Example
<UL>
<LI>Identify items in a numbered list
<LI>Identify items in an unordered list
<LI>Identify items in a directory list
HTML Table:
Tables in HTML are easy to program if you know what you are trying to do.
Tables look like the charts present on many of these slides.
Tables in browsers by default have no borders, if you want to see the edges of your table, you
have to place a border command inside the table tag.
You can also use tables to format pages.
Inside tables, the text is always the default of the browser (black and small), if y u want to change
this font, you must add a <font color=―color‖ and/or size=―x‖> inside ea h ell to make the change.
TABLE
CAPTION
TR
TD
TH
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
1.14 TABLE - (table): The TABLE tag defines a table. Inside the TABLE tag, use the TR tag to define
rows in the table, use the TH tag to define row or column he dings, nd use the TD tag to define table cells.
The TABLE tag can also contain a CAPTION tag, which specifies the caption
for the table.
You can specify the width of the border surrou di g the table and the default
background color of the table. (Ind v dual rows a d cells in the table can have their own background color.)
You can use the CELLSPACING attr bute to specify the distance between cells in the table and the
CELLPADDING attribute to sp cify the distance between the border and content of every cell. If you
specify the width and height of the tabl , the browser will do its best to make the table fit the specified
dimensions, but in some cas s this may not be possible. For example, if the table contains cells that contain
non-wrapping long lin s, the table may not fit in a specified width.
Syntax
<TABLE
ALIGN="LEFT|RIGHT"
BGCOLOR="color"
BORDER="value"
CELLPADDING="value"
CELLSPACING="value"
HEIGHT="height"
WIDTH="width"
COLS="numOfCols"
HSPACE="horizMargin"
VSPACE="vertMargin"
>
...
</TABLE>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
LEFT aligns the table on the left (the default). The content following the table flows to the right
of the table.
RIGHT aligns the table on the right. The content following the table flows to the left of the table.
CENTER aligns the table in the center. Content does not flow on either side.
BGCOLOR="color"sets the color of the background for the table. This color can be verridden by a
BGCOLOR tag in the TH, TR, or TD tags.
BORDER="value" indicates the thickness, in pixels, of the border to draw ar und the table. Give the
value as an integer. A value of 0 means the table has no border. You an also supply the BORDER attribute
without specifying a value for it to indicate that the table has a border of the default thickness.
CELLPADDING="value" determines the amount of space, in pixe s, between the border of a cell and
the contents of the cell. The default is 1.
HEIGHT="height" specifies the height of the table. The defa lt is the optimal height determined by the
contents of each cell. The height value can be a number of pixels, given as an integer, or a percentage of
the height of the page or parent element, given as an integer followed by the percent sign. The table is
scaled to fit the specified height and width.
WIDTH="width" defines the width of the table. The def ult is the optimal width determined by
the contents of each cell.
The width value can be a number of pixels, given as an integer, or a percentage of the width of the
page or parent element, given as an nteger followed by the ercent sign. The table is scaled to fit the
specified height and width.
COLS="numOfCols" indicates how ma y v rtual colum s of equal width fit in the width of the
window. Each actual column in the table occup es a virtual column. You would typically set the COLS
attribute to be equal to the numb r of columns in the table to indicate that all the columns in the table have
the same width.
If the WIDTH att ibute is suppli d, the COLS attribute indicates how many virtual columns fit in
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
the specified width If the WIDTH att ibute is not supplied, the COLS attribute indicates how many
virtual columns fit in the current window or f ame. Each column in the table occupies one of the virtual
columns. Suppose that the WIDTH attribute is "80%" and the COLS attribute is 4.
In this case, each virtual column takes up 20% of the width of the window. Each actual column in
the table occupies a virtual column, so it occupies 20% of the width of the window, so long as the table has
from 1 to 4 columns inclusive. Note, however, that if the minimum width needed to display the contents of
an actual column is greater than the width of a virtual column, then the width of the column is expanded to
fit its contents.
If the table has more actual columns than the COLS value, then the columns in excess of the COLS
value are displayed in the minimum width required to fit their contents, and the other columns divide the
remaining space equally between them.
For example, suppose the table has 4 columns, the WIDTH attribute is "80%", and the COLS value
is 3. What happens here is that the table takes up 80% of the width of the window. The fourth column uses
the minimum width necessary to display the contents of the column. The other 3 columns divide the
remaining width of the table equally between them.
HSPACE="horizMargin" specifies the distance between the left and right edges of the table and any
surrounding content.
VSPACE="vertMargin" specifies the distance between the top and bottom edges of the table and any
surrounding content.
The following example creates a three-column, four-row table, with a yellow background. The
caption "Tables are as easy as one, two, three" is displayed at the bottom of the table.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The last row contains only two cells, which both s an two rows, and the second cell spans three columns.
<TABLE CELLPADDING=3 CELLSPACING=6 BORDER=2>
<CAPTION ALIGN=TOP>
<BIG><BIG>Furniture Mart's Top Sell g Fur iture
</BIG></BIG>
</CAPTION>
<!-- heading row -->
<TR BGCOLOR=#CCCCFF>
<TH>NAME</TH>
<TH>SKU</TH>
<TH>PRICE</TH>
<TH>DESCRIPTION</TH>
</TR>
<!-- end of heading row -->
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<!-- furniture ro s -->
<TR BGCOLOR=#DDEEAA>
<TH>Harriet Smythe Armchair</TH>
<TD>100584</TD><TD>$2150</TD><TD>description goes
here</TD> <TR>
<TR B GCOLOR=#CCFFCC>
<TH>St. Michael Sofa</TH>
<TD>100789</TD><TD>$5000</TD><TD>description goes here</TD>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<TR>
<TR BGCOLOR=#BBDDFF>
<TH>Variety of prints</TH>
<TD>-</TD><TD>$100 to $5000</TD><TD>description goes here</TD>
<TR>
</TD>
<TR>
</TABLE>
TABLE tag but not inside the TD or the TR tags, which indic te t ble cells and table rows respectively.
Navigator 1.1.
Syntax
<CAPTION
ALIGN="BOTTOM"|"TOP">...</CAPTION> ALIGN specifies
the placement of the caption within a table.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
BOTTOM places the caption at the bottom of the table.
TOP places the caption at the top of the table. TOP is the
default. Used Within TABLE
Example See example 1. Simple Table.
TR - (table row) The TR tag sp cifi s a table row. Use the TR tag inside a TABLE tag. The TR tag can
contain TH tags, which indicate table h adings, and TD tags, which indicate table cells.
Syntax
<TR
ALIGN="CENTER|LEFT|RIGHT"
VALIGN="BASELINE|BOTTOM|MIDDLE|TOP"
BGCOLOR="color"
>
...
</TR>
ALIGN specifies the horizontal placement of the table:
CENTER centers the table .
LEFT aligns the table to the left (the default).
RIGHT aligns the table to the right.
VALIGN specifies the vertical placement of the content in the cell:
· BASELINE aligns the content with the cell's baseline.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
BGCOLOR="color" sets the default color of the background of the table row. Table cells defined with
the TD tag inside the row can set their own background color.
TD - (table data)
The TD tag specifies text in a cell in a table. Use the TD tag inside a TR
tag inside a TABLE tag.
You can set the background color of a cell by specifying its BGCOLOR attribute. F r each cell,
you can use the COLSPAN and ROWSPAN attributes to specify how many lumns and r ws the cell spans.
To specify the distance between cells, set the CELLSPACING attribute in the TABLE tag. To
specify the distance between the borders of each cell and its contents, set the CELLPADDING attribute in
the TABLE tag. All cells in a table have the same padding and spacing.
If a cell is empty, that is, the <TD> tag is immediately fo owed by the </TD> tag, the space
occupied by the cell in the table is completely empty. That is, the cell has no content, no background color,
and no border. However, suppose you have a four column t ble, b t you have no data for the second
column in one of the rows. You should still provide the second TD t g for that row, because if you leave it
out the table will close the gap and move the third cell into the second column. The row will end up having
three columns only, and it will not be aligned with the rest of the t ble
If you want an empty cell to look like other cells in the table, you can give it a period or a dash to
indicate that the data is unknown, for example, <TD> - </TD>.
Syntax
<TD
ALIGN="CENTER|LEFT|RIGHT"
VALIGN="BASELINE|BOTTOM|MIDDLE|TOP"
BGCOLOR="colo "
COLSPAN="value"
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
ROWSPAN="valu "
HEIGHT="pixelHeight"
WIDTH="pixelWidth"
NOWRAP="value"
>
...
</TD>
ALIGN specifies the horizontal placement of the contents of the table cell:
CENTER centers the content within the cell.
LEFT aligns the content with the cell's left edge (the default).
COLSPAN="value" indicates the number of columns the cell spans. Give the number as an integer.
ROWSPAN="value" indicates the number of rows the cell spans. Give the value as an integer.
HEIGHT="pixelHeight" specifies the suggested height of the table cell, in pixels.
WIDTH="pixelWidth" specifies the suggested width of the table cell, in pixels.
NOWRAP specifies that the lines within a cell cannot be broken (that is, they do not wrap onto the next
line).
TH - (table heading) The TH tag specifies a table cell whose contents are usually displayed in a
bolder font than those of regular table cells. The intent of the TH tag is that you use it f r lumn r row
headings.
Syntax
<TH
ALIGN="CENTER|LEFT|RIGHT"
VALIGN="BASELINE|BOTTOM|MIDDLE|TOP"
BGCOLOR="color"
COLSPAN="value"
ROWSPAN="value"
HEIGHT="pixelHeight"
WIDTH="pixelWidth"
NOWRAP
>
...
</TH>
ALIGN specifies the horizontal placeme t of the headi g in the table cell:
CENTER centers the content w th n the cell.
LEFT aligns the cont nt with the c ll's left edge (the default).
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
RIGHT aligns the cont nt with the c ll's right edge.
VALIGN specifies the ve tical plac m nt of the contents of the cell:
BASELINE aligns the cont nt with the cell's baseline.
BOTTOM aligns the content with the cell's bottom.
MIDDLE centers the content within the cell (the default).
TOP aligns the content with the cell's top.
BGCOLOR="color" sets the color of the background of the table heading. This color can be overridden
by a BGCOLOR tag in the TD tags within the TH tag.
Table's Attributes
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
border (example)
This specifies the width in pixels of the border around the table
This is in addition to the border around each cell (the "cellspacing").
width
This specifies the width of the table
In pixels (<table width="250">), or
Attributes:
align: Horizontal alignment
Values: "left", "center", "right", "justify", "ch r"
valign: Vertical alignme t
Values: "top", "m ddle", "bottom"
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Table Header (th) and Table Data (td)
Define a table cell
Attributes
HTML Frames:
This section discusses the tags for creating frames and frame sets. A frame is region of a window
that acts as a indow itself. The main window can contain multiple frames, so that different regions of the
FRAME
FRAMESET
NOFRAMES
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The FRAME tag creates a frame, which is an individual, independently scrollable region of a web
browser. You can think of it as a window within a window. The FRAME tag must be used within a
FRAMESET tag.
The FRAMESET tag contains a set of FRAME tags, which each define a frame in the main
window.
Each frame has a distinct URL that determines the content displayed by the frame.
You can specify whether or not a frame has a border, whether or not it has margins, whether or not
the user can resize it dynamically, and whether or not it is scrollable.
Syntax
<FRAME
BORDERCOLOR="color"
FRAMEBORDER="YES"|"NO"
MARGINHEIGHT="marginHeight"
MARGINWIDTH="marginWidth"
NAME="frameName"
NORESIZE
SCROLLING="YES"|"NO"|"AUTO"
SRC="URL"
>
BORDERCOLOR="color" specifies the color of the fr me's borders. Because frames share borders,
Navigator must resolve any border color conflicts.
When neither a FRAME nor a FRAMESET tag governing that FRAME has set
the FRAMEBORDER att ibut , the d fault s tting is YES.
MARGINHEIGHT="ma ginHeight" specifies a margin, in pixels, between the top and bottom edges of
the frame and the frame contents
MARGINWIDTH="marginWidth" specifies a margin, in pixels, between the left and right edges of the
frame and the frame contents.
NAME="frameName" specifies the name of the frame. The value of the NAME attribute must begin ith
an alphanumeric character.
NORESIZE specifies that users cannot resize the frame. If a frame adjacent to an edge is not resizable, the
entire edge is not resizable, and consequently other frames adjacent to that edge are not resizable.
AUTO specifies that the browser determines whether to display scroll bars based on the
size of the frame and its content. If you do not specify a value for SCROLLING, the default value
is AUTO.
SRC="URL" specifies the URL for the document to be displayed in the frame. The URL cannot include
an anchor name; for example FRAME SRC="doc2.html#colors" is invalid. If you do not specify the SRC
attribute, the frame is displayed with no content
The FRAMESET tag contains one or more FRAME tags that each describe a frame.
The only place the FRAMESET tag can be used is in a frame definition d cument, which is an
HTML document that contains the FRAMESET and FRAME tags that des ribe the framesets and frames
that make up a Navigator window.
An HTML document that contains a FRAMESET tag cannot contain a BODY tag.
A frameset can specify that its frames are laid out in rows or co umns If youwant your frameset to
have rows and columns, rather than just rows or columns, you can se FRAMESET tags nested inside
FRAMESET tags.
For example, you could define a frameset that has two col mns, where the first column contains a
frameset that has two rows and the second column cont ins fr meset th t has 4 rows.
You can specify the border thickness for all frames in top-level fr meset. You can also specify whether
or not all frames in a set display their border by default nd wh t color the border uses. Individual frames in
the set can override the default to specify whether or not they displ y their border, and what color their
border uses.
You can specify actions to occur when the wi dow dis laying the frameset gets or loses focus, and
you can specify actions to occur when the frameset s loaded or unloaded.
When you define a link, (using the <A HREF> tag) you can specify in which frame the destination
document is displayed, by giving the name of the frame as the value of the link's TARGET attribute. It is
possible to define a link to change the content of multiple frames in one go by using the ONCLICK
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
attribute of the link. To do this, s t the value of the link's ONCLICK attribute to JavaScript code that
changes the location (sou c ) of one or more frames.
For example, the file f am s t.htm op ns a web page that has three frames. If you click a link in the
left frame, both the other f am s update. You can open the file framtoc.htm and view its source to see the
code for the links that update multiple frames.
The NOFRAMES tag is used inside a FRAMESET tag to provides alternative content for browsers
that cannot display frames
Syntax
<FRAMESET
COLS="columnWidthList"
ROWS="ro HeightList"
BORDER="pixWidth"
BORDERCOLOR="color"
FRAMEBORDER="YES"|"NO"
ONBLUR="JScode"
ONFOCUS="JScode"
ONLOAD="JScode"
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
ONUNLOAD="JScode"
>
...
</FRAMESET>
You must supply at least one of the COLS or ROWS attribues.
COLS="columnWidthList" specifies a comma-separated list of values giving the width of each frame in
the frameset. If one of the values is missing, the browser sizes the corresponding frame to fit the space
available.
The browser may approximate some values to make the total width of the colu ns equal to the
width of the window.
The value of each item in the columnWidthList can be one of the following:
Width of a frame in pixels.
Width of a frame as a percentage of its parent frame or window.
An asterisk (*), which means "as much space as possible," whi h is the space left over
after space has been allocated to all columns that specify their width as pixel value or a percentage
value . The total available left-over space is divided equa y between a l olumns that use an asterisk.
ROWS="rowHeightList" specifies a comma-separated list of val es giving the height of each frame in
the frameset. If one of the values is missing, the corresponding fr me is sized to fit the space available. The
browser may approximate some values to make the tot l height of the rows equal to the height of the
window. Each item in rowHeightList can be one of the following:
An asterisk (*) which mea s "as much s ace as possible," which is the space left over after
space has been allocated to all rows that specify their height as pixel value or a percentage value .
The total available left-over space s divided equally between all rows that use an asterisk.
BORDER="pixWidth" sp cifi s the thickn ss of frame borders for all frames in an outermost frameset. A
setting of 0 causes all f am s in the fram set to have no border between them. A setting of 3 causes a border
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
of 3 pixels If no BORDER tag is pr sent,the default is 5 pixels. The BORDER tag can be used only on an
outermost FRAMESET tag.
BORDERCOLOR="colo " specifies the color of a frame's borders. Because frame borders are shared,
Navigator must resolve any border color conflicts.
Any BORDERCOLOR attribute appearing in the outermost FRAMESET has the lowest priority.
This attribute is overridden by any attribute used in a nested FRAMESET tag.
Finally, any BORDERCOLOR attribute in the current FRAME tag overrides all previous
FRAMESET tag settings. If there is a conflict for two colors of equal priority both set on the same edge,
the behavior is undefined.
FRAMEBORDER determines how frame borders are displayed.
YES results in an outline-3D border.
NO suppresses the 3D border.
When the FRAMEBORDER attribute appears in the FRAMESET tag, it sets a default
FRAMEBORDER value for all frames in that frameset. When the FRAMEBORDER attribute appears in a
FRAME tag, it applies only to that particular frame, overriding any FRAMEBORDER attribute specified
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
by an outer FRAMESET tag. A border shared between frames is plain only if all adjacent frames have the
FRAMEBORDER attribute set to NO. When neither a FRAME nor a FRAMESET tag governing that
FRAME has set the FRAMEBORDER attribute, the default setting is YES.
ONBLUR="JScode" specifies JavaScript code to execute when the window containing the frameset loses
focus.
ONFOCUS="JScode" specifies JavaScript code to execute when the window containing the frameset
gets focus.
ONLOAD="JScode" specifies JavaScript code to execute when the frameset is loaded into
the frame.
ONUNLOAD="JScode" specifies JavaScript code to execute when the frameset is unloaded (exited).
The following example creates a set of two frames. The frameset is kept in a d cument file, such as
index.html, that contains no other information. When users open this page in their web br wser, the
FRAMESET tag loads the individual URLS referenced in the FRAME tags
<HTML>
</HTML>
The two frames appear as columns because COLS is s ecified within the FRAMESET tag. The left frame
uses 30% of the available space, and the r ght frame uses the remaining 70% of the space. By default, the
frames in this example have scrollbars a d are resizable, because no values are specified for the
SCROLLING and NORESIZE attributes.
The following example c at s a frameset that contains a nested frameset. Theoutermost frameset has
two columns. The second column contains a nested frameset that has two rows.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</FRAMESET>
</FRAMESET>
</HTML>
The NOFRAMES tag specifies content that is displayed by browsers that do not know how to display
frames. Browsers that can display frames ignore all text in the NOFRAMES tags unless a file called by a
frame tag is missing or unreachable by the browser. Place the NOFRAMES tag within the FRAMESET
tag.
Syntax
<NOFRAMES>...</NOFRAMES>
HTML Forms:
List of component
Text Text
Area
Label
Button
Check box
Radio button
Menus
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
1. Text
Text component is used to insert a text in web page.
<Input> tag is used to insert a text component in document.
General form
<input type=‖text‖ size=25 value= ― ―>
Text Area
Text Area component is used to feed multiple line of text.
Attribute in text area component.
Row: Row attribute used to denote the total number of rows in the text area.
Column: Column attribute is used to denote the number of column in the text area.
Name: Name attribute is used to denote the name of the text area.
Wrap: Wrap attribute is used to wrap the text inside the text area
<text area> tag is used to insert the text area in the web document
General form:
o <text area cols=‖value‖ rows=‖values‖ >----</text area>
• Example:
o <text area cols=‖50‖ rows=‖40‖ name=‖name‖>---</text area>
Label
Label tag is used to create text box to fill the text.
This tag has starting tag (<label>) and ending t g (</l bel>).
Example
o<label> Name <input type=text size=40>--</label>
Check box
Check box component is used to place the checkbox in the web document.
General form:
o<input type=checkbox> ----- </ put>
Syntax
<MENU>
...
</MENU>
Example
The follo ing example creates a list of three short items:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<P>HTML Menu Example:</P>
<MENU>
<LI> Windows 9x
<LI> Windows NT
<LI> Windows 2000
</MENU>
Forms
FORM
INPUT
INPUT TYPE="BUTTON"
INPUT TYPE="CHECKBOX"
INPUT TYPE="FILE"
INPUT TYPE="HIDDEN"
INPUT TYPE="IMAGE"
INPUT TYPE="PASSWORD"
INPUT TYPE="RADIO"
INPUT TYPE="RESET"
INPUT TYPE="SUBMIT"
INPUT TYPE="TEXT"
SELECT
OPTION
ISINDEX
The FORM tag creates an HTML form. The form can contain interface e ements such as text fields,
buttons, checkboxes, radio buttons, and selection lists that let sers enter text and make choices. Each
interface element in the form must be defined with n ppropri te tag, such as <INPUT> or <SELECTION>.
All elements in the form must be defined between the <FORM> and </FORM> tags. As well as user input
elements, the form can contain other elements such s headings, paragraphs, tables, and so on.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
When the form is displayed in a web browser, the user can fill it out by making choices and
entering text using the interface elements, a d then submit the form by clicking a "Submit" button.
Several kinds of form elements can be def ed usi g the INPUT tag, which uses the TYPE attribute
to indicate the type of elem nt, such as button, checkbox, and so on.
Two other kinds of int rface l m nts you can put in a form are selection lists and text areas.
Selection lists act as menus and a d fin d with the SELECT tag. Multi-line text-entry fields are defined
with the TEXTAREA tag
To enable the form to process the data that the user enters, it must have a "Submit" button, which is
a button defined by an <INPUT TYPE="SUBMIT"> or an <INPUT TYPE="IMAGE"> tag.
The action invoked hen the user clicks a "Submit" button is defined by the ACTION attribute of the
FORM tag. The value of the ACTION attribute is usually a URL that points to a CGI program. A CGI
program runs on a server, processes arguments sent by the form, and returns data to the browser.
The value of the form's METHOD attribute also affects the way the CGI program is invoked. It is
beyond the scope of this reference to provide details of CGI programming, but many fine books are
available on the subject, and also lots of information is available on the web.
You can also define OnClick event handlers for several kinds of input elements. An OnClick event
handler is a piece of JavaScript code that is executed when the element is clicked.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
executes when a "Submit" button in the form is pressed. If the JavaScript code returns false, the form's
action ends there, and the URL specified by the ACTION attribute is not invoked.
If the JavaScript code returns anything else, the URL specified by the ACTION attribute is
invoked. For example, you could use the ONSUBMIT attribute to check whether or not the user really
wants to submit the form.
Name/Value Pairs
When a form is submitted, the data contained in the form is sent to the invoked CGI program as a
series of name/value pairs. The name portion of each pair is the name of an interface ele ent as specified
by its NAME attribute. In most cases the value portion is the value displayed by the ele ent, f r exa ple,
the text displayed in a text field.
Nesting Forms
A document can have multiple forms, but forms cannot be nested -- you ann t have a f rm within a
form. If your document uses positioned HTML content, each form must be ompletely ntained within one
positioned block.
Syntax
<FORM
ACTION="serverURL"
ENCTYPE="encodingType"
METHOD="GET"|"POST"
NAME="formName"
ONRESET="JScode"
ONSUBMIT="JScode"
TARGET="windowName"
>
...
</FORM>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The FORM tag has an optional ONSUBMIT attribute, whose value is a JavaScript event handler that
The ACTION attribute is required if any act on s to occur when the user presses a "Submit" button in the
form.
ACTION="serverURL" sp cifi s the URL of the program to be invoked when the form is submitted.
The action can also be a mailto: URL if the form results are to be mailed to someone.
ENCTYPE="encodingTyp " sp cifi s the MIME encoding of the data sent:
"application/x-www-fo m-u l ncod d" (the default), is usually used if the METHOD attribute has
the value POST.
"multipart/form-data" is used when the form contains a file upload element (INPUT
TYPE="FILE").
METHOD specifies how information is sent to program invoked by submitting the form.
GET (the default) appends the input information to the URL which on most receiving systems
becomes the value of the environment variable QUERY_STRING.
POST sends the input information in a data body that is available on stdin with the data length set
in the environment variable CONTENT_LENGTH.
NAME="formName" specifies the name of the form. The name is not displayed on the form.
JavaScript can use the NAME attribute to differentiate different forms if there are multiple forms on a
page.
ONRESET="JScode" specifies JavaScript code that executes when a user resets the form by using a
RESET button.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
ONSUBMIT="JScode" specifies JavaScript code that executes when a user submits the form by clicking
a "Submit" button.You can use the ONSUBMIT attribute to prevent a form from being submitted; to do
so, put a return statement that returns false in the JavaScript code. Any other returned value lets the form
submit. If you omit the return statement, the form is submitted.
TARGET="windowName" specifies the window that displays the data returned by the invoked program.
Example
The following example creates a form called LoginForm that contains text fields for user name and
password, a submit button, and a cancel button.
The INPUT tag defines a form element that can receive ser input. The TYPE attribute
determines the specific sort of form element to be created. TYPE can be one of the
following:
BUTTON places a button on an HTML form. Use J v Script code to make the button
perform an action you define.
CHECKBOX places a toggle switch on an HTML form, letting the user set a value on or
off.
FILE places an element on an HTML form letting the user supply a file as input. When the
form is submitted, the co te t of the specified file is sent to the server along with the other
form data.
HIDDEN specifies an nv s ble text element. A hidden element is used for passing
information to the s rv r wh n a form is submitted.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
IMAGE plac s an imag , s rving as a custom button, on an HTML form. When a user clicks
an image l m nt, the form is submitted to the server.
PASSWORD plac s a t xt input field on an HTML form. Each character typed in the field is
displayed as a cha acter such as * or a black dot to conceal the actual value.
RADIO places a radio button on an HTML form. Radio buttons can be grouped into sets,
and only one button per set can be selected at a time.
RESET places a reset button on an HTML form. When a user clicks a reset button, all
elements in the form are reset to their default values.
SUBMIT places a submit button on an HTML form. When a user presses a submit button,
the form is submitted.
TEXT places a single line text input field on an HTML form. A text field lets the user enter
text.
INPUT TYPE="BUTTON"
A button apears in the form. You must specify JavaScript code as the value of the ONCLICK
attribute to determine what happens when the user clicks the
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
button.
Syntax
<INPUT TYPE="BUTTON"
NAME="buttonName"
VALUE="buttonText"
ONCLICK="JScode"
>
NAME="buttonName" specifies the name of the button. The name does not appear in the form.
VALUE="buttonText" specifies the text to be displayed in the button.
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks the butt n.
Example
<FORM METHOD=POST ACTION="/cgi-bin/example.cgi">
</FORM>
INPUT TYPE="CHECKBOX" A checkbox is a toggle that the ser can se ect (switch on) or deselect
(switch off.)
Syntax
<INPUT TYPE="CHECKBOX"
CHECKED
NAME="name"
ONCLICK="JScode"
VALUE="checkboxValue"
>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
CHECKED indicates that the checkbox s d splayed with a tick mark to indicate that it is
selected.
NAME="name" specifies the name of the input element. This value is the name portion of the
name/value pair for this el m nt that is s nt to the server when the form is submitted. The name is not
displayed on the form
ONCLICK="JScode" sp cifi s JavaScript code to execute when a user clicks the checkbox.
VALUE="checkboxValue" specifies the value to be returned to the server if the checkbox is selected
when the form is submitted The default value is ON, but you can specify a different value if you want.
When the form is submitted, only the name/value pairs for selected checkboxes are sent to the invoked
CGI program.
Example
INPUT TYPE="FILE" This places an element on an HTML form that lets the user supply a file as input.
When the form is submitted, the content of the specified file is sent to the server as the value portion of the
name/value pair for this input element.
If a form contains a file input element, the value of the ENCTYPE attribute of the FORM tag
should be "multipart/form-data".
Syntax
<INPUT TYPE="FILE"
NAME="name"
VALUE="filename"
>
NAME=name specifies the name of the input element. This value is used as the name p rti n f the
name/value pair for this element that is sent to the server when the form is submitted. The name is not
displayed on the form.
Example
<FORM ENCTYPE="multipart/form-data"
ACTION="/cgi-bin/example.cgi" METHOD="POST">
<P>File name:
<INPUT TYPE="file">
</FORM>
INPUT TYPE="HIDDEN"
A hidden input element is an invisible element whose main purpose is to contain data that the user
does not enter. This data gets sent to the i voked CGI rogram when the form is submitted.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
This tag provides a mechanism for del ver g a value to the CGI program without the user having
entered it, but note that it is not very h dden because the user can discover it by viewing the document
source.
Syntax
<INPUT TYPE="HIDDEN"
NAME="name"
VALUE="value"
>
NAME="name" specifies the name of the input element. This value is the name portion of the
name/value pair sent to the invoked CGI program when the form is submitted. The name is not displayed
on the form.
Example
This example creates a form with a hidden element, DefaultPass, that stores the initial value of the
pass ord field.
example.cgi">
<P>Password:
<INPUT TYPE="password" NAME="password" SIZE="12"
VALUE="treasure">
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
INPUT TYPE="IMAGE"
This places an image, serving as a custom button, on an HTML form. When a user clicks the
image, the form is submitted to the server.
Syntax
<INPUT TYPE="IMAGE"
ALIGN="LEFT"|"RIGHT"|"TOP"|"ABSMIDDLE"|"ABSBOTTOM"|
"TEXTTOP"|"MIDDLE"|"BASELINE"|"BOTTOM"
NAME="name"
SRC="location"
>
ALIGN specifies the alignment of the image in relation to the surrounding text. If y u do n t specify a
value for ALIGN, Navigator uses BOTTOM as the default. The possible values are LEFT, RIGHT, TOP,
ABSMIDDLE, ABSBOTTOM, TEXTTOP, MIDDLE, BASELINE, and BOTTOM. See the section
"IMG" for a description of the values.
NAME=name specifies the name of the input element. This value is used as the name portion
of the name/value pair for this element that is sent to the invoked CGI program when the form is
submitted. The name is not displayed on the form.When Navigator sends the offsets of the image to the
server, it sends them as name.x and name.y.
SRC="location" specifies the URL of the image to be displ yed in the doc ment.
Example
<CENTER><INPUT TYPE="image" SRC="signnow.gif"></CENTER>
INPUT TYPE="PASSWORD" A password element is a text in ut field in which each character typed is
displayed as a character such as * or a black dot to co ceal the actual value.
Syntax
<INPUT TYPE="PASSWORD"
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
MAXLENGTH="maxChar"
NAME="name"
ONSELECT="JScod "
SIZE="charLength"
VALUE="textValu "
>
MAXLENGTH="maxCha " specifies the maximum number of characters a password box can accept.
NAME="name" specifies the name of the input element. This value is used as the name portion
of thename/value pair for this element that is sent to the server when the form
is submitted. The name is not displayed on the form.
ONSELECT="JScode” specifies JavaScript code to execute when a user selects some of the text in the
text element.
SIZE="charLength" specifies the length of the input field, in characters. The value should be an integer.
VALUE="textValue"specifies the initial value of the password, if any.
Example
<P>Password:
INPUT TYPE="RADIO" A radio element is a radio button. A set of radio buttons consists of multiple
radio buttons that all have the same NAME attribute. Only one radio button in the set can be selected at
one time. When the user selects a button in the set, all other buttons in the set are deselected. If one radio
button in a set has the CHECKED attribute, that one is selected when the set is first laid out on the
window.
Syntax
<INPUT TYPE="RADIO"
CHECKED
NAME="name"
ONCLICK="JScode"
VALUE="buttonValue"
>
CHECKED indicates that the radio button is selected.
NAME="name" specifies the name of the input element. This value is used as the name p rti n
of the name/value pair for this element that is sent to the invoked CGI program when the f rm is submitted.
The name is not displayed on the form. All radio buttons that have the same name constitute a radio group;
only one radio button of a group can be set at one time.
ONCLICK="JScode" specifies JavaScript code to execute when a ser c icks the radio button.
VALUE="value” specifies the value that is returned to the server when the radio button is selected and
the form is submitted. Only name/value pairs for radio buttons that are selected are sent to the invoked
CGI program. The value defaults to ON.
Example
The following example creates a radio button group.
<P>Category:
Syntax
<INPUT TYPE="RESET"
NAME="name"
ONCLICK="JScode"
VALUE="label"
>
NAME="name"specifies the name of the input element.
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks the button.
VALUE="label" specifies the text to display on the face of the reset button.
Example
This example displays a text element with the default value CA and a reset button labelled Clear
Form. If the user types a state abbreviation in the text element and then clicks the Clear Form button, the
original value of CA is restored.
<FORM>
<P>State: <INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2">
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</FORM>
INPUT TYPE="SUBMIT" When a user clicks a submit button, the form is submitted, which means that
the ACTION specified for the form is invoked.
Syntax
<INPUT TYPE="SUBMIT"
NAME="name"
VALUE="label">
NAME="name" specifies the name of the input element. The name is not displayed on the form.
VALUE="label" specifies the text to display on the face of the submit button.
Example
<INPUT TYPE="submit" NAME="SubmitButton" VALUE="Done">
INPUT TYPE="TEXT" A text element is a single line text input field in whi h the user an enter text.
Syntax
<INPUT TYPE="TEXT"
MAXLENGTH="maxChars"
NAME="name"
ONBLUR="Scode"
ONCHANGE="JScode"
ONFOCUS="Scode"
ONSELECT="JScode"
SIZE="lengthChars"
VALUE="text"
>
MAXLENGTH="maxChars" specifies the maximum umber of characters a text box can accept.
NAME="name" specifies the name of the put eleme t. This value is used as the name portion
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
of the name/value pair for this eleme t that s se t to the invoked CGI program when the form is
ONBLUR="JScode" specifies JavaScr pt code to execute when the text element loses keyboard
focus.
ONCHANGE="JScode" sp cifi s JavaScript code to execute when the text element loses focus and its
value has been modified
ONFOCUS="JScode" sp cifi s JavaScript code to execute when a user clicks the text element. See the
JavaScript Guide forSee the JavaSc ipt Guide for more information.
ONSELECT="JScode" specifies JavaScript code to execute when a user selects some of the text in the
text element.
Example
<P>Last name:
The SELECT tag defines a selection list on an HTML form. A selection list displays a list of
options from which the user can select an item. If the MUTLIPLE attribute is supplied, users can select
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
multiple options from the list at a time. If the MULTIPLE attribute is not supplied users can select only
one option in the list at a time.
The SIZE attribute specifies how many options in the list are displayed at one time. For multiple-
selection lists, if you do not specify the SIZE attribute, the browser displays some, maybe all, of the
options. For single-selection lists, by default Navigator displays the list as a drop-down menu that initially
shows only one option. The user can click the list to display the rest of the options. If you specify the SIZE
attribute, the list is displayed as a scrolling list that shows the specified number of options, regardless of
The SELECT tag should be used between <FORM> and </FORM> tags. Use the OPTION tag to
define options in the list. When the form containing the selection list is submitted to the server, a
name/value pair is sent for each selected option in the list.
Syntax
<SELECT
NAME="selectName"
MULTIPLE
ONBLUR="JScode"
ONCHANGE="JScode"
ONCLICK="JScode"
ONFOCUS="fScode"
SIZE="listLength"
>
<OPTION...>
...
<OPTION ...>
</SELECT>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
MULTIPLE specifies that multiple tems can be selected. If this attribute is omitted, only one item can be
selected from the list. If multiple select on s enabled, the user usually needs to hold down the Shift key to
select additional items.
NAME="selectName" sp cifi s the name of the select element. This value is the name portion of the
name/value pair sent to the invok d CGI program when the form is submitted. The name is not displayed
on the form.
ONBLUR="blurJScode specifies JavaScript code to execute when the select element loses focus.
ONCHANGE="changeJScode" specifies JavaScript code to execute when the select element loses focus
and its value has been modified
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks an item in the list.
ONFOCUS="focusJScode" specifies JavaScript code to execute when the element gets focus.
SIZE="ListLength" specifies the number of options visible when the form is displayed. If the list
contains more options than specified by size, the list is displayed with scrollbars.
Used WithinFORM
<OPTION> Overnight
</SELECT>
</FORM>
...
</SELECT>
</FORM>
In the following example, all seven options can be chosen, b t bananas are selected by default. The
list is displayed as a scrollable menu that fits four options at a time.
<FORM>
<OPTION>Apples
<OPTION SELECTED>Bananas
<OPTION>Cherries
<OPTION>Oranges
<OPTION>Pineapple
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<OPTION>Figs
<OPTION>Guava
</SELECT>
</FORM>
OPTION - (option in a SELECT list) The OPTION tag specifies an option in a selection list. Use the
OPTION tag inside a SELECTION tag. Wh n the form containing the selection list is submitted to the
server, a name/value pair is sent for each selected option in the list. The value portion of an option is the
value of the VALUE attribute, if it has one, otherwise, it is the text that follows the <OPTION> tag.
Syntax
<OPTION
VALUE="optionValue"
SELECTED
>
...
</OPTION>
VALUE="OptionValue" specifies a value that is returned to the server when the option is selected and
the form is submitted. When no VALUE attribute is present, the value returned is the same as the text
following the <OPTION> tag.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The ISINDEX tag causes the web page to display a text entry field in which the user can type a
string. The intent of this tag is that it "switches on searching" in the page, but in reality, this tag is useful
only if the page is generated by a CGI program.
The intent is that when the user enters text into the text entry field and presses the Return key (or
clicks an appropriate button on the browser), the CGI program is invoked again, with the argu ents
generated from the data in the text field. The browser outputs a new page whose c ntent is deter ined by
what the user entered in the text field.
The CGI program should test for the presence of arguments. If there are n ne, it sh uld display a
default page that includes the ISINDEX tag in the header. If there are arguments, the s ript does whatever
it needs to do. The string entered by the user is the first argument, and the anguage your script uses
determines how you access the first argument.
It is beyond the scope of this reference to provide details on CGI programming, but many fine
books are available on the subject, and lots of information is v il ble on the web.
Syntax
<ISINDEX PROMPT="text" >
PROMPT="text" specifies the text that appears as the search prompt in the browser.
Example
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The following snipp t of code from a CGI program generates the header for an HTML page. When
the page is displayed, it has a text ent y field whose prompt is "Enter a search keyword:".
JavaScript can react to events - A JavaScript can be set to execute when something happens, like
when a page has finished loading or when a user clicks on an HTML element
JavaScript can read and write HTML elements - A JavaScript can read and hange the ontent
of an HTML element
JavaScript can be used to validate data - A JavaScript can be used to va idate form data
before it is submitted to a server. This saves the server from extra processing
JavaScript can be used to create cookies - A JavaScript can be sed to store and retrieve
information on the visitor's computer
The Real Name is ECMAScript. JavaScript is an implement tion of the ECMAScript lang age
standard.ECMAScript is developed and maintained by the ECMA org niz tion. ECMA-262 is the
official JavaScript standard. The language was invented by Brendan Eich at Netsc e (with N vig
tor 2.0), and has appeared in all Netscape and Microsoft browsers since 1996. The develo ment of
ECMA-262 st rted in 1996, and the first edition of was adopted by the ECMA General Assembly
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<html>
<head>
<script type="text/javascript">
document.writeln(“H lo World!);
------
</script>
</head>
<body>
----
----
</body>
</html>
To insert a JavaScript into an HTML page, we use the <script> tag. Inside the <script> tag
we use the type attribute to define the scripting language.
So, the <script type="text/javascript"> and </script> tells where the JavaScript starts and
ends. It is possible to have script code inside the body tag also as shown below. If it is
placed inside the body tag, the script will be executed
<html>
<body>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<script type="text/javascript">
............
</script>
</body>
</html>
Scripts in <head>
Scripts to be executed when they are called, or when an event is triggered, are p aced in fun
tions It is a good practice to put all your functions in the head section, this way they are all in
one place and do not interfere with page ontent.
Example
<html>
<head>
<script type="text/javascript">
function message()
alert("This alert box was called with the o load eve t");
</script>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</head>
<body onload="message()">
</body>
</html>
JavaScripts in a page will be x cut d imm diat ly while the page loads into the browser. This
is not always what we want. Sometimes we want to x cute a sc ipt wh n a page loads, or at a
later event, such as when a user clicks a button. When this is the case we put the script
inside a function
You can place an unlimited number of scripts in your document, and you can have scripts
in both the body and the head section at the same time.
Example
<html>
<head>
<script type="text/javascript">
function message()
</script>
</head>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<body onload="message()">
<script type="text/javascript">
</body>
</html>
JavaScript can also be placed in external files. External JavaScript files often contains
code to be used n several different web pages. External JavaScript files have the file
extension .js. External script annot ontain the <script></script> tags. To use an external
script, point to the .js file in the "src" attribute of the <s ript> tag:
Example
<html>
<head>
</head>
<body>
</body>
</html>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
JavaScript Variables
JavaScript variables are used to hold values or express o s. A variable can have a short
name, like x, or a more descriptive name, like carname. Rul s for JavaScr pt var able
names:
Variable names a case s nsitive (y and Y are two different variables)
var x;
var carname;
After the declaration shown above, the variables are empty (they have no values yet).
However, you can also assign values to the variables when you declare them:
var x=5;
var carname="Volvo";
After the execution of the statements above, the variable x will hold the value 5, and
carname will hold the value Volvo.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
If you assign values to variables that have not yet been declared, the variables will
automatically be declared. These statements:
x=5;
carname="Volvo";
var x=5;
var carname="Volvo";
If you redeclare a JavaScript variable, it will not lose its original value.
var x=5;
var x;
After the execution of the statements above, the variable x will still h ve the v lue of 5.
The value of x is not reset (or cleared) when you redeclare it.
If you declare a variable within a funct on, the var able can o ly be accessed within that
function. When you exit the function, the variable is destroyed. These var ables are called
local variables. You can have local variables with the same name in different functions,
because each s recog zed o ly by the function in which it is declared.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
If you declare a variable outside a function, all the functions on your page can access
it. The lifetime of these variables starts when they a d cla d, and nds when the page
is closed.
Assignment operators are used to assign values to JavaScript variables. Given that x=10
and y=5, the table below explains the assignment operators:
= x=y x=5
== is equal to x==8 is fa se
Logical Operators
Logical operators are used to determine the logic between variables or values. Given
that x=6 and y=3, the table below explains the logical operators:
Conditional Operator
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
JavaScript also contains a conditional operator that assigns a value to a variable based on
some condition.
yntax
variablename=(condition)?value1:value2
Example
Conditional Statements
Very often when you write code, you want to perform different actions for
different decisions. You can use conditional statements in your code to do this.
if statement - use this statement to execute some code only if a specified condition is
true
if...else statement - use this statement to execute some code if the condition is true
and another code if the
condition is false
if...else if....else statement - use this statement to select one of many blocks of code to
be executed
switch statement - use this statement to select one of many blocks of code to be
executed
If Statement
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Use the if statement to execute some code only if a specified condition is true.
Syntax
if (condition)
Note that if is written in lowercase letters. Using uppercase letters (IF) will generate a
JavaScript error!
Example
<script type="text/javascript">
var time=d.getHours();
if (time<10)
document.write("<b>Good morning</b>");
</script>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
If...else Statement
Use the if....else statement to execute some code if a condition is true and another code if the
condition is not true.
Syntax
if (condition)
else
Example
<script type="text/javascript">
//If the time is less than 10, you will get a "Good morning" greeting.
//Otherwise you will get a "Good day" greeting.
document.write("Good morning!");
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
}
else
document.write("Good day!");
</script>
Use the if....else if...else statement to select one of several blocks of code to be exec ted.
Syntax
if (condition1)
else if (condition2)
else
Example
else
document.write("<b>Hello World!</b>");
</script>
Use the switch statement to select one of many blocks of code to be executed.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Syntax
switch(n)
case 1:
case 2:
default:
JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
Alert Box
An alert box is often used if you want to make sure information comes through to the user.
When an alert box pops up, the user will have to click "OK" to proceed.
Syntax
alert("sometext");
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Example
<html>
<head>
<script type="text/javascript">
function show_alert()
</script>
</head>
<body>
</html>
Confirm Box
A confirm box is often used if you want the user to verify or accept something. When a
confirm box pops up, the user ill have to click either "OK" or "Cancel" to proceed. If the
user clicks "OK", the box returns true. If the user clicks
Syntax
confirm("sometext");
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Example
<html>
<head>
<script type="text/javascript">
function show_confirm()
if (r==true)
else
</script>
</head>
<body>
</html>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Prompt Box
A prompt box is often used if you want the user to i ut a value before entering a page.
When a prompt box pops up, the user will have to click either "OK" or "Ca cel" to roceed
after entering an input value. If the user clicks "OK" the box returns the input value. If the
user cl cks "Ca cel" the box returns null.
Syntax
prompt("sometext","defaultvalue");
Example
<html>
<head>
</script>
</head>
<body>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</html>
JavaScript Functions
JavaScript Functions
To keep the browser from executing a script when the page loads, you can put your script
into a functi n. A functi n contains code that will be executed by an event or by a call to the
function. You may call a functi n fr m anywhere within a page (or even from other pages if
the function is embedded in an external .js file). Functi ns can be defined both in the <head>
and in the <body> section of a document. However, to assure that a fun tion is read/l aded
by the browser before it is called, it could be wise to put functions in the <head> section.
Syntax
function functionname(var1,var2,...,varX)
some code
}
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The parameters var1, var2, etc. are variables or values passed into the function. The { and the } defines the
start and end of the function. The word function must be written in lowerc se letters, otherwise a JavaScript
error occurs! Also note that you must call a function with the exact same ca itals s in the function n me
Example
<html>
<head>
alert("Hello World!");
</script>
</head>
<body>
<form>
</body>
</html>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The return Statement
The return statement is used to specify the value that is returned from the function. So, functions that are
going to return a value must use the return statement. The example below returns the product of two
numbers (a and b):
Example
<html>
<head>
<script type="text/javascript">
function product(a,b)
{
return a*b;
</script>
</head>
<body>
<script type="text/javascript">
document.write(product(4,3));
</script>
</body>
</html>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
JavaScript Loops
Often when you write code, you want the same block of code to run over nd over g in in a
row. Instead of adding several almost equal lines in a script we can use loops to perform t
sk like this.
The for loop is used when you know in advance how many times the script should run.
Syntax
code to be executed
Example
The example below defines a loop that starts with i=0. The loop will continue to run as long
as i is less than, or equal to 5. i ill increase by 1 each time the loop runs.
Note: The increment parameter could also be negative, and the <= could be any comparing statement.
Example
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</script>
</body>
</html>
The while loop loops through a block of code while a specified condition is true.
Syntax
while (variable<=endvalue)
code to be executed
Example
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The example below defines a loop that starts w th =0. The loop will continue to run
as long as i is less than, or equal to 5. i will increase by 1 each time the loop ru s:
Example
<html>
<body>
while (i<=5)
i++;
</script>
</body>
</html>
The do...while loop is a variant of the while loop. This loop will execute the
block of code ONCE, and then it will repeat the loop as long as the specified
condition is true.
Syntax
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
code to be executed
while (variable<=endvalue);
Example
The example below uses a do...while loop. The do...while loop will always be executed
at least once, even if the condition is false, because the statements are executed before
the condition is tested:
Example
<html>
<body>
<script type="text/javascript">
var i=0;
d
o
i++;
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
}
while (i<=5);
</script>
</body>
</html>
The break statement will break the loop and co t ue executi g the code that follows after
the loop (if any).
Example
<html>
<body>
var i=0;
for (i=0;i<=10;i++)
if (i==3)
break;
</script>
</body>
</html>
The continue statement will break the current loop and continue with the next value.
Example
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
if (i==3)
continue;
document.write("<br />");
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
}
</script>
</body>
</html>
The for...in statement loops through the elements of an array or through the roperties of
an object.
Syntax
code to be executed
Note: The code in the body of the for... n loop s xecuted once for each element/property.
Note: The variable a gum nt can be a nam d variable, an array element, or a property of an
object.
Example
Example
<html>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<body>
<script type="text/javascript">
var x;
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";
for (x in mycars)
</script>
</body>
</html>
JavaScript Events
Events
By using JavaScript, we have the ability to create dynamic web pages. Events are actions
that an be dete ted by JavaScript. Every element on a web page has certain events which
can trigger a JavaScript For example, we an use the onClick event of a button element to
indicate that a function will run when a user c i ks on the button. We define the events in
the HTML tags.
Examples of events:
A mouse click
A web page or an image
loading
Mousing over a hot spot on the web
page
Selecting an input field in an HTML
form
Submitting an HTML form
A keystroke
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Events are normally used in combinat on w th fu ct o s, a d the function will not be
executed before the event occurs.
Event Association
Events are associated with HTML tags. The d finitions of the events described below are as
follows:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
JavaScript Objects
Date
Math
String, Number,
Boolean
RegExp
window (Global Obejct)
Of the above objects, the most widely used one is the String object. Objects re nothing b
t special kind of data. Each object has Properties and Methods associated with it.
property is the v l e th t is tagged to the object. For example let us consider one of the
properties associated with the most o ul rly used String object - the length property.
Length property of the string object returns the length of the string th t is in other words
the number of characters present in the string.
General syntax of using the length property of the stri g object is as below:
variablename.length
Here variablename is the name of the var able to wh ch the stri g is assigned and length is the
keyword.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<html>
<body>
var exf="Welcome"
document. rite(exf.length)
</script>
</body>
</html>
Method of an Object:
Method of an object refers to the actions than can be performed on the object. For example
in String Object there are several methods available in JavaScript.
<html>
<body>
<script type="text/javascript">
var exf="Welcome"
document.write(exf.toUpperCase())
</script>
</body>
</html>
WELCOME
In the above script since the method toUpperCase is applied to the string object exf
which has value initialized as Welcome all letters get converted as upper case and hence
the output is s bove.
var exf="Welcome"
Method
charAt()
charCodeAt()
concat()
indexOf()
lastIndexOf()
match()
replace()
search()
slice()
split()
substr()
substring()
toLowerCase()
toUpperCase()
valueOf()
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Date object of Java Script is used to work with date and times. General syntax for defining
Date bject in Java Script is as follows:
In the above new is a keyword which creates an instance of object and Date() defines
variablename as Date Object.
For example:
In the above example, variable exf is defined as Date object which h s c rrent d te nd time as
its initial value.
setSeconds()- Sets the seconds for a specified date accordi g to local time.
setMinutes() - Sets the minutes for a spec f ed date accord g to local time.
setHours() - Sets the hours for a specif ed date accord g to local time.
setDate() - Sets the day of the month for a specified date accord g to local time.
setMonth() - Sets the month for a specified date accord g to local t me.
setYear() - Sets the year (d pr cat d) for a sp c f d date according to local time.
setFullYear() - Sets the full y ar for a sp cifi d date according to local time.
getDay() - Returns day of the week for a specified date according to local time
getDate() - Returns day of the month for a specified date according to local time.
exf.setFullYear(2020,0,20)
As e have seen setFullYear() is used for Setting the full year for a specified date
according to local time. In the above example the Date object exf is set to the specific
date and year 20th January 2020
<html>
<body>
<script type="text/javascript">
var exforsys=new Date();
var currentDay=exforsys.getDate();
var currentMonth=exforsys.getMonth() + 1;
var currentYear=exforsys.getFullYear();
</script>
</body>
</html>
11/15/2006
JavaScript Math object is used to perform mathematical tasks. But unlike the String and
the Date object which requires defining the object, Math object need ot be defi ed. Math
object in JavaScript has two main attributes:
Properties
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Methods
The JavaScript has eight math matical valu s and this can be accessed by using the
Math Object. The eight mathematical values a e:
PI
square root of 2 denoted as
SQRT2
square root of 1/2 denoted as
SQRT1 2
natural log of 2 denoted as
LN2
natural log of 10 denoted as
LN10
base-2 log of E denoted as
LOG2E
The ay of accessing these values in JavaScript is by using the word Math before these values
namely as
Math.E
Math.LOG10E and so on
There are numerous methods available in JavaScript for Math Object. Some of them are
mentioned below namely:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
ceil(x) - Returns the smallest integer greater than or equal to x. (round up).
cos(x) - Returns cosine of x, where x is in radians.
exp(x) - Returns ex
floor(x) - Returns the largest integer less than or equal to x. (round down)
log(x) - Returns the natural logarithm (base E) of x.
max(a, b) - Returns the larger of a and b.
<html>
<body>
<script type="text/javascript">
document.write(Math.round(5.8))
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</script>
</body>
</html>
This is because the round() method rounds the number given in argument namely here 5.8
to the nearest integer. It rounds .5 up hich gives 6.
<html>
<body>
<script type="text/javascript">
</script>
</body>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</html>
The above example uses the max() method of the Math object which returns the largest of
the two numbers given in arguments of the max method.
The Boolean object is used to convert a non-Boolean value to a Boolean value (true or fa se)
Met Description
hod
Converts a Boolean value to a string, nd
toSt returns the res lt Returns the primitive value
ring of a Boole n object
()
valu
eOf
()
Number Object
Method Description
toFixed(x) Formats a number with x numbers of digits after the decimal point
String Object
Syntax
or more simply:
Regular expressions are used to do sophisticated pattern matching, which can often be
helpful in form validation. For example, a regular expression can be used to check
whether an email address entered into a form field is syntactically correct. JavaScript
supports Perl-compatible regular expressions.
Assuming you know the regular expression pattern you are going to use, there is no real
difference between the two; however, if you don't know the pattern ahead of time (e.g,
you're retrieving it from a form), it can be easier to use the RegExp() constructor.
The regular expression method in JavaScript has two main methods for testing
strings: test() and exe (). The exec() Method
The exec() method takes one argument, a string, and checks whether that string contains one
or more mat hes of the pattern specified by the regular expression. If one or more matches is
found, the method returns a result array with the starting points of the matches. If no match
is found, the method returns n ll.
The test() method also takes one argument, a string, and checks whether th t string
contains a match of the pattern specified by the regular expression. It returns true if it
does cont in m tch nd f lse if it does not. This method is very useful in form validation
scripts. The code sam le below shows how it c n be used for checking a social security
number. Don't worry about the syntax of the regular ex ression itself. We'll cover that
shortly.
<head>
<script type="text/javascript">
</script>
</head>
<body>
<form name=”f1”>
</body>
</html>
Code Explanation
Next, a function called f1() is created. This function takes one argument: ssn, which is
a string. The function then tests to see if the string matches the regular expression pattern
by passing it to the regular expression object's test() method. If it does match, the function
alerts "VALID SSN". Otherwise, it alerts "INVALID SSN".
function f1(ssn)
A form in the body of the page provides a text field for inserting a social security
number and a butt n that passes the user-entered social security number to the f1()
function.
<form >
Flags
Flags appearing after the end slash modify how a regular expression works.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The i flag makes a regular expression case insensitive. For ex m le, / eiou/i m tches
all lowercase and uppercase vowels.
The g flag specifies a global match, meaning that all matches of the s ecified pattern
should be returned.
A caret (^) at the beginning of a r gular xpr ssion indicates that the string being
searched must start with this pattern.
A dollar sign ($) at the end of a egular expression indicates that the string being
searched must end with this pattern.
The follo ing symbols affect the number of occurrences of the preceding character: ?, +,
*, and {}.
A questionmark (?) indicates that the preceding character should appear zero or one times in
the pattern.
* The pattern foo? can be found in "food" and "fod", but not "faod".
A plus sign (+) indicates that the preceding character should appear one or more times in the
pattern. *
The pattern fo+ can be found in "fod", "food" and "foood", but not "fd".
A asterisk (*) indicates that the preceding character should appear zero or more times in the
pattern.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Curly brackets with one parameter ( {n} ) indicate that the preceding character should
appear exactly n times in the pattern.
* The pattern fo{3}d can be found in "foood" , but not "food" or "fooood".
Curly brackets with two parameters ( {n1,n2} ) indicate that the preceding character
should appear between n1 and n2 times in the pattern.
* The pattern fo{2,4}d can be found in "food","foood" and "fooood", but not "fod" or
"foooo d".
Curly brackets with one parameter and an empty second paramenter ( {n,} ) indicate that
the pre eding hara ter should appear at least n times in the pattern.
The pattern fo\dd can be found in "fo1d", "fo4d" a d "fo0d", but not in
Backslash-w ( \w ) repres nts any word charact r (letters, digits, and the underscore ( ) ).
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
* The pattern fo\wd can be found in "food", "fo d" and "fo4d", but not in "fo*d".
The pattern fo\sd can be found in "fo d", but not in "food". Backslash-
The pattern f[aeiou]d can be found in "fad" and "fed", but not in "food", "faed" or "fd".
The pattern f[aeiou]{2}d can be found in "faed" and "feod", but not in
When used after the first character of the regular expression, the caret ( ^ ) is used for
negation.
The pattern f[^aeiou]d can be found in "fqd" and "f4d", but not
The pattern foo$|^bar can be found in "foo" and "bar", but not "foobar".
Escape Character : \
* The pattern fo\.d can be found in "fo.d", but not in "food" or "fo4d".
A more practical example has to do matching the delimiter in soci l security numbers.
Examine the following regular expression.
Within the caret (^) and dollar sign ($), wh ch are used to specify the beginning and end
of the pattern, there are three sequences of digits, optionally separated by a hyphen or a
space. This pattern will be matched in all of following strings (and more).
123-45-6789
123 45 6789
123456789
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
123-45 6789
123 45-6789
123-456789
The last three strings are not ideal, but they do match the pattern. Back references can be
used to make sure that the second delimiter matches the first delimiter. The regular
expression would look like this.
^\d{3}([\- ]?)\d{2}\1\d{4}$
The \1 refers back to the first subpattern. Only the first three strings listed above match this
regular expression.
Regular expressions make it easy to create powerful form validation functions. Take
a look at the following example.
<html>
<head>
<script type="text/javascript">
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
function validate()
</script>
</head>
<body>
<form name=”form”>
*Password must be between 6 and 10 characters and can only contain letters and digits.
</form>
</body>
</html>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Code Explanation
This code starts by defining regular express o s for an email address and a password. Let's
break each one down.
1. The caret (^) says to sta t at the b ginning. This prevents the user from entering
invalid characters at the beginning of the email add ss
(\w+[\-\.])* allows for a s qu nce of word characters followed by a dot or a dash. The
* indicates that the pattern can be repeated ze o or mo e times. Successful patterns
include "ndunn.", "ndunn-", "nat.s.", and "nat-s-".
\w+ allows for one or mo e wo d characters.
(\ +\.)+ allo s for a sequence of word characters followed by a dot. The + indicates that
the pattern can be repeated one or more times. This is the domain name without the last
portion (e.g, without the "com" or "gov").
6. [A-Za-z]+ allo s for one or more letters. This is the "com" or "gov" portion of the
email address.
The dollar sign ($) says to end here. This prevents the user from entering invalid
characters at the end of the email address.
var RE PASSWORD = /^[A-Za-z\d]{6,8}$/;
The caret (^) says to start at the beginning. This prevents the user from entering
invalid characters at the beginning of the password.
The dollar sign ($) says to end here. This prevents the user from entering invalid
characters at the end of the pass ord.
Exercises:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Construct a reg exp to validate a text field which should be used to accept only a string
composed by 3 letters, one space, 6 numbers, a "-" and a number such as MJHJ
123456-6
Ans: /^[A-Za-z]{4}\s\d{6}\-\d{1}$/
1. Proper Name
2. Initial
5. Username
first name
middle initial
last name
city
state
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
zip
username
Document Object
Each HTML document load d into a b ows r window becomes a Document object. The
Document object provides access to all HTML elem nts in a pag , f om within a script.
It describes the JavaScript array object including parameters, properties, and methods.
Parameters
arrayLength
Properties
index
input
Methods
chop() - Used to truncate the last character of a all strings that are part of an array. This
meth d is n t defined so it must be written and included in your code.
exclamations.chop()
Look out
Duck
concat()
grep(searchstring) - Takes an array and returns those arr y element strings th t contain
matching strings. This method is not defined so it must be written and included in your
code.
lines, finish
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
* join(delimiter) - Puts all l m nts in the array into a string, separating each element with
the specified delimiter.
limit;lines;finish;complete;In;Out
pop() - Pops the last string off the array and returns it. This method is not defined
so it must be written and included in your code.
Out
push(strings) - Strings are placed at the end of the array. This method is not defined
so it must be written and included in your code.
shift() - Decreases array element size by one by shifting the first element off the
array and returning it. This method is not defined so it must be written and included in
your code.
word = words.shift()
Out
* sort() - Sorts the array elements in d ct o ary order or usi g a compare function passed to
the method.
word = words.sort()
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
In,Out,complete,finish,limit,lin s
splice() - It is used to take elements out of an array and replace them with those specified.
In the below example the element starting at element 3 is removed, two of them are removed
and replaced with the specified strings. The value returned are those values that are replaced.
This method is not defined so it must be written and included in your code.
complete, In
String("limit;lines;finish;complete;In;Out")
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
word = words.shift("limit","lines")
The array, words, will be:
limit, lines,finish, complete, In, Out
Form validation
Form validation is the process of checking that a form has been filled in correctly
before it is processed. For example, if your form has a box for the user to type their
email address, you might w nt yo r form handler to check that they've filled in their
address before you deal with the rest of the form. Form v lid tion is s ally done with
JavaScript embedded in the Web page
UNIT –IV
PHP - Working principle of PHP - PHP Variables - Constants - Operators – Flow Control and
Looping - Arrays - Strings - Functions - File Handling - File Uploading – Email Basics - Email with
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
attachments - PHP and HTML - Simple PHP scripts - Databases with PHP
PHP (Hypertext Preprocessor) is a server-side scripting language designed for web development. It
is one of the most popular programming languages for building dynamic websites and web
applications.
1. Client sends a request: When a user visits a website or interacts with a web application, their
web browser sends a request to the web server.
2. Web server processes the request: The web server (e.g., Apache, Nginx) receives the request
and identifies that the requested file has a .php extension.
3. PHP parser: The web server passes the PHP file to the PHP parser, which is installed on the
server. The PHP parser reads the PHP code line by line and executes it.
4. PHP code execution: PHP is a server-side scripting language, which means that the PHP code is
executed on the server. The PHP interpreter processes the PHP code and generates the
corresponding output.
5. Database and external resources: PHP can interact with databases (e.g., MySQL, PostgreSQL)
and other external resources (e.g., APIs, file systems). It can retrieve data from databases,
modify data, and perform various operations.
6. HTML generation: PHP is often used in combination with HTML (Hypertext Markup
Language). Within the PHP code, HTML can be embedded, allowing dynamic generation of
HTML content based on the logic and data processing performed by the PHP code.
7. Output generation: Once the PHP code is executed, it generates output, typically in the form of
HTML, CSS, JavaScript, or other web content. This output is sent back to the web server.
8. Server response: The web server receives the output generated by PHP and sends it back as a
response to the client's request.
9. Client receives the response: The client's web browser receives the server's response, which
may include HTML, CSS, JavaScript, or other resources. The browser renders the received
content and displays it to the user.
Throughout this process, PHP allows developers to write dynamic and interactive web
applications by incorporating programming logic, database interactions, file operations, and more. It
enables the creation of websites that can respond to user input, handle form submissions, process
data, and generate personalized content.
PHP, variables
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
PHP, variables are used to store and manipulate data. They are containers that hold values and
can be referenced and manipulated throughout the script. Here are some key points about PHP
variables:
1. Variable Declaration: In PHP, you don't need to explicitly declare variables before using them.
You can simply assign a value to a variable, and PHP will automatically create it. For example:
In the above code, $age and $name are variables storing an integer and a string value,
respectively.
2. Variable Names: PHP variable names start with the dollar sign ($) followed by a letter or
underscore. They can contain alphanumeric characters and underscores but must begin with a
letter or underscore. Variable names are case-sensitive, so $age and $Age would be treated as
different variables.
3. Variable Types: PHP variables are dynamically typed, meaning that you don't need to specify
their data type explicitly. The data type is determined based on the value assigned to the
variable. PHP supports various data types, including integers, floats, strings, booleans, arrays,
objects, and more.
4. Variable Assignment: You can assign a value to a variable using the assignment operator (=).
The value can be a literal or the result of an expression. For example:
$x = 10 ; $y = $x + 5 ;
In this case, $x is assigned the value 10, and $y is assigned the result of the expression $x + 5,
which is 15.
5. Variable Scope: PHP variables have different scopes, which determine their visibility and
accessibility within different parts of the script. The three main scopes are:
Global Scope: Variables defined outside of any function or class have a global scope and can be
accessed from anywhere in the script.
Local Scope: Variables defined inside a function have a local scope and are only accessible
within that function.
Static Scope: Using the static keyword within a function allows a variable to retain its value
between function calls.
6. Variable Output: To output the value of a variable, you can use the echo or print statements.
For example:
These are some fundamental aspects of PHP variables. They play a crucial role in storing and
processing data within PHP scripts, enabling dynamic and flexible behavior in web
applications.
PHP constants
In PHP, constants are similar to variables but with one key difference: their values cannot be
changed once they are defined. Constants are useful for storing values that remain constant
throughout the execution of a script. Here are the key points about PHP constants:
1. Constant Declaration: Constants are declared using the define() function or the const keyword.
The general syntax for defining a constant is:
define ( 'CONSTANT_NAME' , value);
or
For example:
In the above code, PI and WEBSITE_NAME are constants with values 3.14159 and
"MyWebsite" respectively.
2. Naming Conventions: Constants' names are usually written in uppercase letters, although it's
not a strict requirement. Using uppercase letters helps distinguish constants from variables and
makes them more readable.
3. Accessing Constants: Once defined, constants can be accessed throughout the script without the
need for a leading dollar sign ($). To access a constant, simply use its name. For example:
echo PI; // Outputs: 3.14159 echo WEBSITE_NAME; // Outputs: MyWebsite
4. Constant Scope: Constants have a global scope and can be accessed from anywhere in the
script, including inside functions and classes.
5. Predefined Constants: PHP provides several predefined constants that are available for use
without the need for explicit declaration. These include PHP_VERSION, PHP_OS,
PHP_EOL, and more. They provide information about the PHP environment and can be useful
in certain situations.
6. Constant Values: Constant values can be of any scalar type: integers, floats, booleans, or
strings. They cannot be assigned the result of an expression or a function call.
7. Best Practices: It is a common practice to define constants in a centralized location, such as a
configuration file, to make them easily accessible and maintainable throughout the script.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Constants are beneficial when you have values that should not be modified during the execution
of your PHP script, such as configuration settings, mathematical constants, or fixed strings. By
using constants, you can ensure the integrity of these values and avoid accidental modification.
PHP operators
1. Arithmetic Operators:
Addition (+): Adds two operands.
Subtraction (-): Subtracts the second operand from the first.
Multiplication (*): Multiplies two operands.
Division (/): Divides the first operand by the second.
Modulus (%): Returns the remainder of the division operation.
Increment (++) and Decrement (--): Increase or decrease the value of a variable by one.
2. Assignment Operators:
Assignment (=): Assigns a value to a variable.
Addition assignment (+=): Adds the right operand to the left operand and assigns the result to
the left operand.
Subtraction assignment (-=): Subtracts the right operand from the left operand and assigns the
result to the left operand.
Multiplication assignment (*=): Multiplies the right operand with the left operand and assigns
the result to the left operand.
Division assignment (/=): Divides the left operand by the right operand and assigns the result to
the left operand.
Modulus assignment (%=): Computes the modulus of the left operand with the right operand
and assigns the result to the left operand.
3. Comparison Operators:
Equal to (==): Checks if the left operand is equal to the right operand.
Identical to (===): Checks if the left operand is equal to the right operand and of the same type.
Not equal to (!= or <>): Checks if the left operand is not equal to the right operand.
Not identical to (!==): Checks if the left operand is not equal to the right operand or not of the
same type.
Greater than (>): Checks if the left operand is greater than the right operand.
Less than (<): Checks if the left operand is less than the right operand.
Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right
operand.
Less than or equal to (<=): Checks if the left operand is less than or equal to the right operand.
4. Logical Operators:
AND (&&): Returns true if both the left and right operands are true.
OR (||): Returns true if either the left or right operand is true.
NOT (!): Returns the opposite boolean value of the operand.
5. String Operators:
Concatenation (dot .): Concatenates two strings together.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Concatenation assignment (dot equals .=): Appends the right operand to the left operand and
assigns the result to the left operand.
These are just a few examples of PHP operators. PHP also provides bitwise, array, and ternary
operators, among others, for performing specific operations.
PHP provides several flow control and looping structures to control the execution flow of your
code. These structures allow you to make decisions, repeat code blocks, and iterate over data.
Here are the main flow control and looping structures in PHP:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
1. If statement: The if statement allows you to execute a block of code conditionally based on a
specific condition. It has the following syntax:
You can also use elseif to add additional conditions within the same statement.
2. Switch statement: The switch statement allows you to select one of many blocks of code to be
executed. It is useful when you have multiple conditions to check against a single variable.
Here's an example:
switch (variable) { case value1: // Code to execute if variable matches value1 break ; case
value2: // Code to execute if variable matches value2 break ; default : // Code to execute if
variable doesn't match any case break ; }
3. While loop: The while loop executes a block of code as long as a specific condition is true.
The condition is checked before each iteration. Here's an example:
Do-while loop: The do-while loop is similar to the while loop, but it checks the condition after
each iteration. This guarantees that the code block is executed at least once. Here's an example:
4. For loop: The for loop is commonly used when you know the number of iterations in advance.
It has three parts: initialization, condition, and increment. Here's an example:
5. Foreach loop: The foreach loop is used to iterate over arrays and objects. It automatically
assigns the current element to a variable for each iteration. Here's an example:
foreach ( $array as $value ) { // Code to execute for each element in the array }
6. Break and continue: Both break and continue are used within loops to control the flow.
break terminates the loop and continues executing the code after the loop, while continue
skips the current iteration and moves to the next iteration.
These flow control and looping structures provide powerful tools to handle different scenarios
in PHP programming, enabling you to control the flow of execution and manipulate data
efficiently.
Arrays in PHP: Arrays in PHP are used to store multiple values in a single variable. They can
hold different data types such as strings, numbers, or even other arrays. PHP provides several
functions and operations to manipulate arrays. Here's an example of creating an array and
accessing its elements:
Strings in PHP: Strings in PHP are sequences of characters enclosed in quotes. PHP offers
various functions to manipulate strings, including concatenation, splitting, searching, and
replacing. Here's an example demonstrating some string operations:
$name = "John" ; $age = 25 ; // Concatenating strings $greeting = "Hello, " . $name . "!
You are " . $age . " years old." ; echo $greeting ; // Output: Hello, John! You are 25 years old.
// String length echo strlen ( $name ); // Output: 4 // Searching for a substring echo
strpos ( $name , "oh" ); // Output: 1 (position of "oh" in "John") // Replacing part of a string
$newString = str_replace ( "John" , "Jane" , $name ); echo $newString ; // Output: Jane
Functions in PHP: Functions in PHP allow you to encapsulate reusable blocks of code. They
help improve code organization, reusability, and maintainability. Here's an example of defining
and calling a function in PHP:
// Defining a function function greet($name) { echo "Hello, " . $name . "!" ; } // Calling the
function greet ( "John" ); // Output: Hello, John!
You can also pass parameters to functions, return values, use default arguments, and more. PHP
provides a wide range of built-in functions, and you can create your own custom functions to
suit your requirements.
These are just basic examples of working with arrays, strings, and functions in PHP. PHP offers
much more functionality and numerous built-in functions to work with these concepts. Refer to
the official PHP documentation for more detailed information and examples:
https://www.php.net/manual/
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
PHP provides various functions and techniques for file handling and file uploading. Here's an
overview of how you can handle file uploads in PHP.
1. HTML Form: Create an HTML form with an input field of type "file" to allow users to select a
file for uploading. Set the form's enctype attribute to "multipart/form-data" to handle file
uploads.
html code
2. PHP Server-side Handling: In the PHP script that receives the file upload request (in this
example, "upload.php"), you can handle the uploaded file using the $_FILES superglobal
variable.
php code
<?php if( isset ( $_POST [ "submit" ])){ $targetDir = "uploads/" ; // Directory to save the
uploaded files $targetFile = $targetDir . basename ( $_FILES [ "fileToUpload" ][ "name" ]);
$uploadOk = 1 ;
if( $check !== false ) { echo "File is an image - " . $check [ "mime" ] . "." ; $uploadOk = 1 ; }
else { echo "File is not an image." ; $uploadOk = 0; } } // Check if the file already exists
if ( file_exists ( $targetFile ))
{ echo "Sorry, file already exists." ; $uploadOk = 0 ; } // Check file size (optional)
{ echo "Sorry, your file is too large." ; $uploadOk = 0 ; } // Limit allowed file types (optional)
$allowedExtensions = array( "jpg" , "jpeg" , "png" , "gif" );
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed." ;
$uploadOk = 0 ;
if ( $uploadOk == 1 )
{ echo "The file " . basename ( $_FILES [ "fileToUpload" ][ "name" ]). " has been uploaded." ;
else
}
} ?>
This script checks various conditions such as file type, size, and existence, and then moves the
uploaded file to the specified directory if all checks pass.
Remember to create the "uploads" directory in the same location as your PHP script to store the
uploaded files.
Note: It's crucial to implement additional security measures such as validating file types,
restricting file sizes, and handling file name collisions to enhance security and prevent
unauthorized access or file execution.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Sending emails with attachments in PHP involves a few steps. Here's a basic example to get
you started:
1. Ensure that PHP's built-in mail() function is properly configured on your server. Check your
PHP configuration file (php.ini) or consult your hosting provider to ensure email functionality
is enabled.
2. Create a form or gather the necessary information (sender, recipient, subject, message) and the
file to be attached.
3. Use the $_FILES superglobal array to access the uploaded file. Make sure your form has the
enctype attribute set to "multipart/form-data" for file uploads.
phpCopy code
<?php // Sender and recipient details
$sender = 'sender@example.com' ;
$recipient = 'recipient@example.com' ;
$subject = 'Email with Attachment' ;
$message = 'Please find the attached file.' ;
// File details
$file = $_FILES [ 'attachment' ];
$attachment_path = $file [ 'tmp_name' ];
$attachment_name = $file [ 'name' ]; // Email headers
$headers = "From: $sender\r\n" ;
$headers .= "Reply-To: $sender\r\n" ;
$headers .= "MIME-Version: 1.0\r\n" ;
$headers .= "Content-Type: multipart/mixed; boundary=" . uniqid ( rand (), true ) . "\r\n" ;
// Email body
$body = "--" . uniqid ( rand (), true ) . "\r\n" ;
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n" ;
$body .= "Content-Transfer-Encoding: 7bit\r\n" ;
$body .= "\r\n" ;
$body .= "$message\r\n" ;
$body .= "--" . uniqid ( rand (), true ) . "\r\n" ;
$body .= "Content-Type: application/octet-stream; name=\"$attachment_name\"\r\n" ;
$body .= "--" . uniqid ( rand (), true ) . "--" ; // Send the email $mail_sent = mail( $recipient ,
$subject , $body, $headers ); if ( $mail_sent ) { echo "Email sent successfully with
attachment." ; } else { echo "Failed to send email." ; } ?>
Note: The example above uses the mail() function, which is a basic email-sending function in
PHP. For more advanced email handling, you might consider using a library like PHPMailer or
SwiftMailer, which provide more features and flexibility.
The combination of PHP and HTML is often used to create dynamic web pages and build web
applications. Here's a basic example of PHP code embedded in HTML:
html code
<!DOCTYPE html>
<html>
<head>
</title>
</head>
<body>
<?php // PHP code $name = "John Doe"; echo "Hello, " . $name . "! This is a dynamic
message."; ?> <p> Thanks for visiting! </p>
</body>
</html>
In the above example, the PHP code (<?php ?>) is used to define a variable $name and echo a
dynamic message containing the variable's value. When the PHP code is executed on the server,
it generates the HTML content that will be sent to the browser. The resulting page will display
the dynamic message "Hello, John Doe! This is a dynamic message."
PHP and HTML can work together to create more complex web applications, including e-
commerce sites, content management systems, and web-based software. They provide the
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
necessary tools for server-side processing, data manipulation, and generating dynamic content
based on user input or database interactions.
1 .Hello World:
php code
<?php
$number1 = 10 ;
$number2 = 20 ;
<?php
$number = 15 ;
if ( $number % 2 == 0 )
} ?>
These are just a few examples to get you started. You can build upon them and explore more
complex functionalities based on your requirements.
PHP is a popular programming language for web development, and it provides several options
for working with databases. Here are some commonly used databases with PHP:
3. SQLite: SQLite is a lightweight and file-based relational database engine. It is suitable for
smaller applications or when you need a self-contained database file. PHP has built-in
4. support for SQLite, allowing you to work with SQLite databases using PDO or SQLite-speciic
functions.
5. Oracle: Oracle is a powerful and widely used enterprise-grade relational database management
system. PHP provides the OCI8 extension, which enables connectivity to Oracle databases.
OCI8 offers a comprehensive set of functions for interacting with Oracle databases.
These are just a few examples of databases commonly used with PHP. Depending on your
specific needs, there are many other databases and PHP extensions available that you can
explore.
php code
<?php
$username , $password );
catch (PDOException $e ) {
?>
In this example, you need to replace the placeholders ($servername, $username, $password,
and $dbname) with your actual database details.
Remember to handle your database credentials securely, such as storing them in a separate
configuration file outside of the web root directory and ensuring proper access permissions.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
UNIT -V
Servlets: Java Servlet Architecture – Servlet Life cycle- Form GET and POST actions -
Sessions – Cookies – Database connectivity - JDBC
Creation of simple interactive applications - Simple database applications
Host Objects
JavaScript supports three types of objects: native, host, and user-defined. Native
objects are objects supplied by the JavaScript language. String, Boolean, Math,
and Number are examples of native objects.
Host objects are JavaScript objects that provide special access to the host
environment. They are provided by the browser for the purpose of interaction with
the loaded document. In a browser environment,
window
document
objects are host objects. Several other browser host objects are informal, de facto
standards. They are: alert, prompt, confirm.
DOM
The primary function of the Document Object Model is to view, access, and
change the structure of an HTML document separate from the content cont
ined within it.
The DOM will provide you with methods and properties to retrieve, modify,
pdate, and delete parts of the document you are working on. The properties of
the Document Object Model are used to describe the web page or document
and the methods of the Document Object Model are used for working with
parts of the web page.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
In DOM, HTML document is represented in tree like structure. It constructs
a hierarchical tree structure for a HTML docume t to traverse a d to mani
ulate the document.
For example,
<html>
<head>
</head>
<body>
</body>
</html>
The node directly above a node is the parent of that node. The nodes one level
directly below another node are the children of that node. Nodes at the same level,
and with the same parent, are siblings. The set of nodes any number of levels below
another node are the dendants of that node.
Types of nodes
There are many types of nodes in the DOM document tree that specifies
what kind of node it is. Every Object in the DOM document tree has
properties and methods defined by the Node host object.
The DOM represents an HTML document as a tree of Node objects. With any
tree structure, one of the most common things to do is traverse the tree,
examining each node of the tree in turn. The following program shows one way
to do this.
<html>
<head>
<script>
function countTags(n)
{ // n is a Node
</script>
</head>
</body>
</html>
Output
The ability to traverse all nodes in a document tree gives us the power to find
specific nodes. When programming with the DOM API, it is quite common to
need a particular node within the document or a list of nodes of a specific type
within the document.
This code finds <table> tags and returns elements in the order in which they appear in the
document.
<html>
<head>
<script type="text/javascript">
function f1()
alert(document.getElementById("p1").nodeName);
</script>
</head>
<body>
</body>
</html>
Output
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
In the above prog am the method getElementById() finds the specific element
and nodeName is used property return the specific element name.
DOM API lies in the features that allow you to use JavaScript to dynamically
modify documents. The follo ing examples demonstrate the basic techniques of
modifying documents and illustrate some of the possibilities.
The follo ing example includes a JavaScript function named reverse( ), a sample
document, and an HTML button that, hen pressed, calls the reverse( ) function,
passing it the node that represents the <body> element of the document. The reverse( )
function loops backward through the children of the supplied node and uses the
removeChild( ) and appendChild( ) methods of the Node object to reverse the order of
those children.
<html>
<head><title>Reverse</title>
<script>
var numkids = kids.length; // Figure out how many children there are
</script>
</head>
<body>
<pre>
paragraph #1
paragraph #2
paragraph #3
</pre>
<form>
</body>
</html>
when the user clicks the button, the order of the paragraphs nd of the button re reversed.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
The follo ing program illustrates how to change the element style using DOM properties
and methods.
<html>
<head>
<script type="text/javascript">
function f1()
document.getElementById("p1").style.backgroundColor="red";
</script>
</head>
<body>
</body>
</html>
The method getElementById() gets the paragraph element in the document and the
property style is used to change the background color of the paragraph to “red” as
shown below.
<html>
<head>
<script type="text/javascript">
function f1()
{
var o=document.getElementById(" 1");
o.style.color="red";
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
}
function f2()
{
var o=document.getElementById("p1");
o.style.color="blue";
</script>
</head>
<body>
Me
</p>
<form>
</form>
</body>
</html>
Output
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<html>
<head>
<script type="text/javascript">
function f1()
function f2()
</script>
</head>
<body id="p1">
<pre>
</pre>
</body>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
</html>
After pressing the Question button, it adds the content, How re you?” to the
HTML document and after pressing the Answer button, it replaces the content
“How re you?” with “Fine, thank you”
<html>
<head>
node.removeChild(node.childNodes[0]);
</script>
</head>
<body >
</body>
</html>
After pressing the “Remove” button, the element “Question” is removed from the document
The combination of
HTML
JavaScript
DOM
is sometimes referred to as Dynamic HTML (DHTML). Web pages that
inc ude scripting are often called dynamic pages. Similarly, web server
response can be static or dynamic
Servlet Overview
The following figure illustrates the servlet program worki g rinci le.
Types of Servlet
Generic Servlet
HttpServlet
Running Servlets
Java Servlets are programs that run on a Web or A lication server and act as a
middle layer between a request coming from a Web browser or other HTTP clie t
a d databases or applications on the HTTP server.
Using Servlets, you can collect input from users through web page forms, present
records from a database or another source, and create web pages dy am cally.
Java Servlets often s rve the same purpose as programs implemented using the
Common Gateway Interface (CGI). But Servlets off s v al advantag s in comparison
with the CGI.
Performance is significantly b
tt r.
Servlets execute within the address space of a Web server. It is not necessary to
create a separate
process to handle each client request.
Servlets are platform-independent because they are written in Java.
Java security manager on the server enforces a set of restrictions to protect the
resources on a
server machine. So servlets are trusted.
Servlets Architecture:
Servlets Tasks:
1. Read the explicit data sent by the clients (browsers). This incl des n HTML form on a
Web page or it could also come from an applet or a custom HTTP client progr m.
Read the implicit HTTP request data sent by the clients (browsers). This includes
cookies, media types and compression schemes the browser underst nds, nd so forth.
3. Process the data and generate the results. This rocess may require talking to a database,
executing an RMI or CORBA call, invoki g a Web service, or com uting the response
directly.
Send the explicit data (i.e., the docume t) to the clients (browsers). This document can be
sent in a variety of formats, includ ng text (HTML or XML), binary (GIF images), Excel,
etc.
Send the implicit HTTP respo se to the cl e ts (browsers). This includes telling the
browsers or other clients what type of docume t s be g retur ed (e.g., HTML), setting
cookies and caching parameters, and other such tasks.
Servlets Packages:
Java Servlets are Java class s un by a w b s rver that has an interpreter that
supports the Java Servlet specification
These classes implement the Java Servlet and JSP specifications. At the time of
writing this tutorial, the versions are Java Servlet 2.5 and JSP 2.1.
Java servlets have been created and compiled just like any other Java class. After
you install the servlet packages and add them to your computer's Classpath, you
can compile servlets with the JDK's Java compiler or any other current compiler.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Servlets - Life Cycle
A servlet life cycle can be defined as the entire process from its creation till the
destruction. The following are the paths followed by a servlet
The init method is designed to be called only once. It is called when the servlet is
first created, and n t called again for each user request. So, it is used for one-time
initializations, just as with the init meth d f applets.
The servlet is normally created when a user first invokes a URL corresponding to
the serv et, but you an also specify that the servlet be loaded when the server is first
started.
When a user invokes a servlet, a single instance of each servlet gets created, with
each ser request resulting in a new thread that is handed off to doGet or doPost as
appropriate. The init() method simply creates or loads some data that will be used
throughout the life of the servlet.
// Initialization code...
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
}
The service() method is the main method to perform the actual task. The servlet
container (i.e. web server) calls the servic () m thod to handle r quests coming
from the client( browsers) and to write the formatted response back to the cli nt.
Each time the se ver c iv s a qu st for a servlet, the server spawns a new thread
and calls service. The service() method ch cks the HTTP r qu st type (GET,
POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc
methods as appropriate.
ServletResponse response)
The service () method is called by the container and service method invokes doGe,
doPost, doPut, doDelete, etc. methods as appropriate. So you have nothing to do with
service() method but you override either doGet() or doPost() depending on what type
of request you receive from the client.
The doGet() and doPost() are most frequently used methods with in each service
request. Here are the signature of these two methods.
A GET request results from a normal request for a URL or from an HTML
form that has no METHOD specified and it should be handled by doGet()
method.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
public void doGet(HttpServletRequest request,
HttpServletResponse response)
// Servlet code
A POST request results from an HTML form that specifically lists POST as the
METHOD and it should be handled by doPost() method.
// Servlet code
After the destroy() method is called, the servlet object is marked for garbage
collection. The destroy
method definition looks like
this:
}
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Architecture Diagram:
The
follo ing figure depicts a typical servlet life-cycle nario.
First the HTTP requests coming to the server are delegated to the servlet
container.
The servlet container loads the servlet before invoking the service()
method.
Then the servlet container handles multiple requests by spawning multiple
threads, each thread executing the service() method of a single instance of the
servlet.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
{
("text/html"); PrintWriter out = response.getWriter(); try
r {
e
s
p
o
n
s
e
s
e
t
C
o
n
t
e
n
t
T
y
p
e
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
type of the response
//
cont
ent // used to create a response as a Html doc
out.println("<html>");
---------------------
---------------------
out.println("</html>");
}catch(Exception e){}
}}}
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Servlets - Examples
Servlets are Java classes which service HTTP requests and implement the javax.servlet.Servlet
interface. Web application developers typically write servlets that extend
javax.servlet.http.HttpServlet, an abstract class that implements the Servlet interface and is specially
designed to handle HTTP requests
Following is the sample source code structure of a servlet example to write Hello World:
import javax.servlet.*;
import
javax.servlet.http.*;
Do required initialization
message = "Hello
World";
}
Output:
where the portion after the ? is called a query string. Here it is “name=Raj&color=Red”,
in which name and color are parameter names and “Raj” and “Red” are parameter values.
Printthis is a servlet filename and servelt is a directory. Multiple parameters are separated
by &. All parameter values are strings by default. Parameter names and values can be any
8-bit characters.
The following methods are used to process these parameter data in sevlets.
The following program explains how to process these p r meter n mes nd v lues as
well as path of the resource using servlet.
Example program
import java.io.*;
import java.util.*;
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
import javax.servlet.*;
import javax.servlet.http.*;
try {
out.println("<html>");
out.println("<head>"); out.println("<title>Servlet
Ne Servlet</title>"); out.println("</head>");
out.println("<body>");
hile(para1.hasMoreElements())
{
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
out.println("Parameter name:"+para1.nextElement());
String id = request.getParameter("id");
out.println("Name:" + name);
out.println("Id:" + id);
out.println("</body>");
out.println("</html>");
}catch(Exception e){}
}
}
}
Enumeration para1=request.getParameterNames();
while(para1.hasMoreElements())
out.println("Parameter name:"+para1.nextElement());
}
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Output:
Parameter value can be the value of value attribute of any form control
or it may be the value received from the user by the cont ol at un time.
For example,
The follo ing program explains how to send the data to server
from a web page and the same how to receive it from the server.
html>
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
<head>
</head>
<body>
<pre>
</pre>
</body>
</html>
Servlet for processing the data coming from this web page
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
response.setContentType("text/html");
try {
out.println("<html>");
out println("<body>");
String s4 = request.getParameter("t4");
out.println("Age:" + s3);
out.println("E-mail:" + s4);
out.println("</body>");
out.println("</html>");
} catch(Exception e) {}
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Output
GET:
Important note:
class not s. The soft copy for these topics will be given
later.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
DBC (Java Database Connectivity) is a Java API that provides a standard way for Java
programs to interact with relational databases. It allows Java applications to perform
various database operations such as connecting to a database, executing SQL queries, and
retrieving or updating data.
Here are the basic steps involved in establishing database connectivity using JDBC:
1. Import the JDBC library: First, you need to import the JDBC library into your Java program.
You can do this by including the appropriate JDBC driver JAR file in your project or by
using a build tool like Maven or Gradle to manage dependencies.
2. Load the JDBC driver: Before you can connect to a database, you need to load the
appropriate JDBC driver using the Class.forName() method. The driver class name varies
depending on the specific database you are using. For example, if you're using MySQL, you
would load the driver using Class.forName("com.mysql.jdbc.Driver").
4. Create a statement: Once you have a database connection, you can create a Statement or a
PreparedStatement object to execute SQL queries. Statements allow you to execute static
SQL queries, while PreparedStatements are used for queries with parameters.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
6. Process the results: If your query returns results, you can iterate over the ResultSet object
to retrieve the data. You can use methods like next(), getString(), getInt(), etc., to
access the values returned by the query.
7. Close the resources: After you have finished using the ResultSet, Statement, and
Connection objects, it's important to close them to release database and system resources.
You can use the close() method on these objects to do so.
These are the basic steps involved in establishing database connectivity using JDBC. It's
important to handle exceptions appropriately, use connection pooling for performance
optimization, and follow best practices for secure database access.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
UNIT – I
A node is any addressable device connected to a network whereas the host is a more specific
descriptor that refers to a networked general-purpose computer rather than a single purpose device
(such as a printer).
Router operates like electronic postal workers that evaluate and forward packets between
networks.
3. Define protocol.
it allows for reuse of layers that are not s ecific to rticul r pplic tion.
5. Define encapsulation.
A port is a logical chan el to an application running on a host. ie., The applications running on
the host mach es are u iquely identified by port numbers.
Protocol tunneling is the process of encapsulating one protocol within another protocol that
operates on the same layer.
The components are host, an optional port, path, filename, section and query string.
12. Define URL encoding.
URL encoding involves replacing all unsafe and nonprintab e hara ters with a percent sign
(%) followed by two hexadecimal digits corresponding to the character’s ASCII value.
TCP:
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
Connection oriented tra sport protocol
Sends data as a stream of bytes
Guarantee of delivery
UDP:
Connection l ss p otocol
Datag am s vice
2. Multicasting
Handles storage
Handles security
Provides scalability
Handles accounting and distribution
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
17. What are the necessities of using HTML forms?
Gathering user information
Conducting Surveys
Interactive services
18. What are the sequences of steps for each HTTP request from a c ient to the server?
Making the connection
Making a request
The response
Closing the connection
It is a simple page description language, which enables document creation for the .
Handles storage
Handles security
Provides scalability
Handles accounting and distribution
UNIT II
platform, whereas Netscape’ s Web servers run on all major platforms, including
Windows NT platform, OS/2 and UNIX.
27. What are ISAPI (Internet Server API) and NSAPI (Netscape Server API)
ISAPI (Internet Server API): An API for Microsoft’s IIS (Internet Inf
rmati n Server) Web server. ISAPI enables programmers to develop Web-based appli
ati ns that run much faster than conventional CGI programs because they’re more
tightly integrated with the Web server. In addition to IIS, several Web servers from
companies other than Microsoft support ISAPI.
NSAPI -Netscape Server API: An API for Netscape’s Web servers. NSAPI
enables programmers to create Web-based applications that are more sophisticated and
run much faster than applications based on CGI scripts.
The biggest diffe ence b tw n the two is that a Java applet is persistent. This means that once it
is started, it stays in memo y and can fulfill multiple requests. In contrast, a CGI
program disappears once it has fulfilled a request. The persistence of Java applets
makes them faster because there’s no asted time in setting up and tearing down the
process.
gro ing popularity of OLE (object linking and embedding), applets are becoming
more prevalent. A well-designed applet can be invoked from many different
applications.
Web browsers, who are often equipped with Java virtual machines, can
interpret applets from Web servers. Because applets are small in files size, cross-
platform compatible, and highly secure (can’t be used to access users©hard drives),
they are ideal for small Internet applications accessible from a browser.
31. What do you mean by Server-side?
Occurring on the server side of a client-server system. For example, on
the World Wide Web, CGI scripts are server-side applications because they run on
the Web server. In contrast, JavaScript scripts are client-side because they are
executed by your browser (the client). Java applets can be either server-side or
client- side depending on which computer (the server or the client) executes them.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
3.How the sending device will indicate that it has finished sending a message
4.How the receiving device will indicate that it has received a message
An ActiveX control is similar to a Java applet. Unlike Java applets, however, ActiveX
controls have full acc ss to the W ndows operating system. This gives them much more
power than Java appl ts, but with this power comes a certain risk that the applet may
damage software or data on your machine. To control this risk, Microsoft developed a
registration system so that b ows s can id ntify and authenticate an ActiveX control before
downloading it Another diffe ence between Java applets and ActiveX controls is that Java
applets can be w itten to un on all platforms, whereas ActiveX controls are currently limited
to Windo s environments Related to ActiveX is the scripting language VBScript that enables
Web authors to embed interactive elements in HTML documents.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
35.Explain about HTTP Connection.
It is a communication channel between web browser and web server. It begins on the
client side with the browser sending a request to the web server for a document.
Request Header Fields are
From
Reference
If modified since
Pragma
User Agent
In CGI, the server prepares the environment variables before it laun hes the CGI
script. These represent the current state of the server that is asking for the informati n. The
environment variables are not set from the command line but are created on the fly, and lasts
only until that particular script is finished. Each script gets its own unique set of variables and
multiple scripts can be executed at once, each in its own environment
These are mnemonics for standard input and standard o tp t, two predefined stream /
file handles. Each process already inherits these two h ndles already open. From the script’s
point of view, STDIN is what comes from the browser via the server when the post method is
used, and the STDOUT is where it writes its output b ck to the browser. The script
picks up the environment variables and reads STDIN s ropri te. It then does whatever it was
designed to do and writes its output to STDOUT.
The request methods tell the scr t how it was invoked. Based on this information, the
script decides how to act. The request method is passed to the script using environment variable
called REQUEST- METHOD. The two most common request methods used are GET and
POST.
GET
GET is a qu st for data, the same method used for obtaining static
documents. The GET method sends qu st info mation as parameter tacked onto the
end of the URL. These parameters are pass d to the CGI program in the environment
variable QUERY-STRING.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
E g : If the sc ipt is called myprog.exe and is invoked from a link with the
form <A HREF="cgi-bin/myp og.exe? lname=blow&fname=joe"> The
REQUEST_METHOD
ill be the string GET, and the QUERY STRING will contain lname=blow &
fname=joe. A mandatory question mark separates the name of the script from the
beginning of the QUERY STRING. If a slash is used instead of the question mark; the
server passes
POST
POST operation occurs when the browser sends data from a fill -in form to the
server. With POST, the QUERY_STRING mayor may not be blank, depending on the
server.The data from a POSTed query gets passed from the server to the script using
STDIN. Because STDIN is a stream and the script needs to know how much valid data
is waiting, the server also Supplies another variable, CONTENT_LENGTH, to indicate
the size in bytes of the incoming "data.
information. Hence this information has to be supplied by the script itself. Failure will
result in the browser receiving information that it does not know how to display.
HTTP specification requires that the URL data should be encoded in such a way
that it can be used on almost any hardware and software platforms. Information spe ified
in this way is called URL encoded. If parameters are passed as a part of query string r
path information, they will take the form of ‘Name-Value’ pairs.
variablel=valuel&variable2=value2& so on for each variable defined in the form
The variables or name value pairs are separated by ©&©.Real ampersand is es aped -that
is, encoded as a two-digit hexadecimal value representing the character Escaped
characters are indicated in URL-encoded string by the percent (%) sign. Blank spaces are
rep aced by ©+©sign. Before the script can deal with the data it has to parse and decode
it. The script scans through the string looking for an ampersand. When it is fo nd the
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
string is broken from that point. The variable©s name is every thing up to the eq l sign in
the string and the value is every thing after the equal sign. The script continues to p rse
the original string for the next ampersand, and so on until the original string is exh usted.
After the variables are separated, they are decoded as follows.
A CGI p og am can crash without damaging the server, since it only has
limited access to the s v .
Reduces the bu d n of s rv r
a Sends p epa ed messages / mails e customer reply
State is a general term that includes "everything about your situation" and the specifics
vary based on the application. In a word processor, the state of the application would include
which windows are open, where they are on the screen, and what files you most recently used. In
a web application, the state would include any data that you had entered, the results of any
queries that you had run, and your security access information (e.g. whether you have logged in
to the site).
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
UNIT III
Multicasting sends data from one host to many different hosts, which
are in the multicast group.
Protocol handlers are used to retrieve the web objects using appli
ation specific protocols. The protocols are specified in the URL referencing
the obje t
setURL(URL u, Sring protocol, Stri g host, int port, String file, String ref) -
assigns values to the URL’s f elds.
Content handlers are used to retr eve objects via an URLConnection object.
Objects that have methods that can be called across virtual machines are remote
objects.
A stub for a remote object is the client side proxy for the remote object. A client side
stub is responsible for:
A skeleton for a remote object is a server side entity that contains a method which
dispatches calls to the actual remote object implementation. The skeleton is responsible
for 1.Unmarshaling arguments from the marshal stream.
2.Making the up-call to the actual remote object.
3.Marshalling the return value of the call to an exception onto the Marshall stream
66. Write down the Socket object methods to get inform tion bout socket.
getInetAddress ()- displays which remote host the Socket is connected to
getPort () -displays which port the Socket is connected to on the remote host.
3. getLoca1Port ()- to fi d the ort umber for the local end of a connection
UNIT IV
Style sheets are collections of style information that are applied to plain text.
Style information includes font attributes such as type size, special effects
(bold,italic,underline), color and alignment. Style sheets also provide broader formatting
instructions by specifying values for quantities such as line spacing and left and right
margins.
1.Linked Styles -Style information is read from a separate file that is specified in
the <LINK> tag
3.Inline Styles -Style information is placed inside an HTML tag and applies to all
content between that tag and it companion closing tag.
71. What are the style precedence rules when using multiple approaches?
Inline styles override both linked style sheets and style information st red in
the document head with <STYLE> tag.
1.font-family
2.font-size
3.font-weight
4.font-style
5.font-variant
A DTD is a set of ules that specifies how to use XML markup. It contains
specifications for each element, including what the element’s attributes are, what
values the attributes can take on and what elements can be contained in others.
What are the XML rules for distinguishing between the content of a document and
the XML markup element?
1.The start of XML markup elements is identified by either the less than symbol
(<) or the ampersand (&) character
2.Three other characters, the greater than symbol (>), the apostrophe or single
quote (‘) and the double quotation marks (“) are used by XML for markup.
3.To use these special characters as content within your document, you must use
the corresponding general XML entity.
Scriptlets enable you to create small, reusable web applications that can be
used in any web page. Scriptlets are created using HTML, scripting and Dynamic
HTML. To include them in an HTML document use the <OBJECT> tag.
4.Response -It transmits information from the web server to web browser
5.Request -It retrieves information from the browser for processing at the server.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
81. What is global.asa file?
The global.asa file is a Active Server Application file you can track and manage
the application and session events, variables and objects. When you start the app ication
the server will load the global.asa file into memory.
7.Flush
Directives are JSP elements that provide global information about an entire JSP page.
85. Write do n the various attributes for the page directives in JSP.
The page directive defines information that will be globally available for
that Java Server Page,
language
extends
import
session
buffer
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
contenttype
A proxy server is a host that makes Internet request on behalf of other machines
on the network, Proxy servers are often used to cache frequently requested files or to
onitor Internet use within a Corporation.
89.Define SSI.
Server Side Includes (SSI) gives you a way to insert the content of another file
into a file before the web server processes it.
Data binding is DHTML feature that lets you e sily bind individ al elements
in your document to data from another source such s d t b se or comma delimited text
file.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
UNIT- 5
ON LINE APPLICATION
91. What is meant by Plug-in?
2.Products displayed from the online store re ssoci ted with links to
detailed descriptions of the products
3.You are able to compare the roduct to simil r roducts b sed on the features
and
pricing.
4.It also brings you to the web sites of the roduct manufacturer for
more information.
PART B
How do you use frame collections to access objects in a separate frame on your
ebpage
Describe the servlet architecture and the various information invoked by the servlet
container.
What is a session? Explain how client state is maintained using session and also
explain about session tracking and session management using an example
List the XML syntax rules in detail and Explain how a XML do ument an be
displayed on a browser
Consider the database table with the following structure Student (studentname,
Reg. No.
INFORMATION TECHNOLOGY
FOURTH SEMESTER
(Regulations 2021)
K-Level CO
PART – B ( 5 13 = 65 marks)
OR
b) Create a Web page and divide the web page into four equal
13 4 2
parts each individual part displays different web page
12. a) i) Name some new features which were not present in HTML but are added to
HTML5? (7)
13 6 1
ii) Write an HTML code to form a table to show the below values in a tabular
form with heading as Roll No., Student name, Subject Name, and values as.(6)
OR
b) (i) Explain the capabilities of web client and web server. (7)
13 4 1
(ii) Write and explain HTTP request message format. (6)
13 a) (i) Write a Java Script to display a welcome message using alert whenever a
button of a html form is pressed.
13 5 2
(ii) Write CSS code that defines five classes of paragraph with different
background.
OR
14. a) (i) Write a Java Script program that asks for user name, password, mail id,
phone number field in HTML file and validate them by taking assumptions(7) 13 5 2
(ii) Demonstrate about the types of cascading style sheets.(6)
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
OR
(ii)Explain how tables can be inserted into a HTML document with an example. 13 4 2
(6)
OR
b) Explain HTML forms in detail along with form elements, attributes and
methods. Write an HTML document to provide a form that collect name and 13 4 2
telephone numbers.
PART C (1 15 = 15)
16. a) (i) List and explain in detail various selector strings. (8) 15 6 2
(ii) Explain the features of cascading style sheets. (7)
OR
b) List and describe the CSS Border Style Properties in detail with
15 4 2
illustration.
Marks 62 118 - - -
% 34.4 65.4 - - -
Note: Including the Choice, the Total Marks will be 180. Each CO must cover around 30 marks or
16.67%.
Prepared By Approved By
INFORMATION TECHNOLOGY
FOURTH SEMESTER
(Regulations 2021)
K-Level CO
7 Rewrite the code segment to store current server time in session using Java Servlet API. 6 5
9 Formulate the three methods that are central to the life cycle of the servlet. 6 5
PART – B ( 5 13 = 65 marks)
Marks K-Level CO
OR
i) Write PHP Program to print whether given number is odd or even. (6).
b) 13 4 4
Construct a PHP script to compute the Square root, Square, Cube and
12. a) 13 6 4
Quad of 10 numbers.
OR
Design a simple HTML form and accept the user name and display the
13 a) 13 6 4
name through PHP echo statement.
OR
OR
Consider a database that has a table Employee with two columns Employee Id
and Name. Assume that the administrator user id and password to access to
b) access the database table are Scott and Tiger. Write a JDBC program that can 13 5 5
query andprint all entries in the table employee. Make the database using type
2 driver databases.
ST. PETER'S COLLEGE OF ENGINEERING & TECHNOLOGY: CHENNAI
Affiliated to Anna University, Chennai & Approved by AICTE
OR
Explain the ways of storing and accessing information using cookies and
b) 13 5 5
handling associated issues.
PART C (1 15 = 15)
Note: Application/Design/Analysis/Evaluation/Creativity/Case K-
Marks CO
Study questions. Level
OR
Marks - - - 88 92
% - - - 48.8 51.2
Note: Including the Choice, the Total Marks will be 180. Each CO must cover around 30 marks or
16.67%.
Prepared By Approved By