Professional Documents
Culture Documents
T
M
L
5 ANKIT SINGH 1
ANKIT SINGH 2
HTML Introduction
What is HTML?
Communication: The Internet enables easy and rapid communication across the
world through a number of services, such as emails, chats, and social networks.
Data transfer: The Internet helps in transferring a large amount of data, such as
files and Images.
</body>
</html>
ANKIT SINGH 3
Example Explained:-
The doctype declaration is not case sensitive. All cases are acceptable:
Like
<!DOCTYPE html>
<!doctype HTML>
ANKIT SINGH 4
The <HTML> Declaration
The Hypertext Markup Language (HTML), the standard programming language for
describing the contents and appearance of Web pages. an HTML document. The opening
HTML tag, and the closing HTML tag, < 'HTML),
<TITLE>
<MEAT>
<BASE>
<STYLE>
<LINK>
<SCRIPT>
<NOSCRIPT>
ANKIT SINGH 5
The <BASE> Declaration
The <Base> tag is used to URL (Uniform Resource Locator) or address for all the
related links on a page. The hosting Images in a website located in a particular
directory. To access these Images, you can specify path of the directory by using the
href attribute of the <Base> tag.
Example:-
<HTML>
<HEAD>
<BASE href=”D:\Images\”>
</HEAD>
<BODY>
</BODY>
</HTML>
Example:-
<HTML>
<HEAD>
<style>
h1 {
color: red;
ANKIT SINGH 6
font-size: 14px;
P{
Font-style:italic;
</style>
</HEAD>
<BODY>
</BODY>
</HTML>
Example:-
ANKIT SINGH 7
<! DOCTYPE HTML>
<HTML>
<BODY>
<SCRIPT type="text/javascript">
var name=prompt("Please Enter Your Name","like John");
alert("Welcome "+name);
</SCRIPT></BODY>
</HTML>
prompts users to enter name by using the prompt() function and displays this name
in a message box by using the alert() function.
The alert ( ) function code displays the message, Welcome John when the OK
button in the prompt is clicked.
<HTML>
<BODY>
ANKIT SINGH 8
<SCRIPT type=”text/javascript”>
<SCRIPT>
</BODY>
</HTML>
The <Noscript> tag code display the text Your browser does not support scripts
Applying Headings
The HTML allows SIX levels of headings, ranging from <H1> to <H6> The <H1> tag
is used to define the topmost heading, whereas the <H6> tag is used to define the
lowest-level heading
Example:-
<HTML>
<HEAD></HEAD>
<BODY>
</BODY>
</HTML>
ANKIT SINGH 9
Adding paragraphs
You can use the new paragraphs in a HTML
<p>
<DETAILS>
<SUMMARY>
<P>
The <p> tag add a new paragrphs in the HTML Document.the <p>
Tag is a container the browsers automatically add one line space before and
after the content.
Example:-
<BODY>
</BODY>
<DETAILS>
The additional content that a user can view or hide as per requirement to be
used details tag in your HTML document.
<BODY>
ANKIT SINGH 10
<DETAILS>
</DETAILS>
</BODY>
<SUMMARY>
A heading for the <DETAILS> TAG Users can click this heading to view or hide
the details.
Example:-
<BODY>
<DETAILS>
<P>ADCA,DCA,BASIC,TALLY,HTML,JAVA,C,C++,C#,COREL DROW,PHOTO
SHOP</P>
</DETAILS>
</BODY>
ANKIT SINGH 11
Defining a Layout
The layout of a Web page and separate individual elements or content should be
displayed on the Web page.
<DIV>
<SPAN>
<DIV>
The <DIV>tag is used to define a section in a document. It is used to group of
sections as blocks
<SPAN>
The <span> tag enables you to group and apply styles to inline elements. The tag is
dependent on the style attribute on a particular word and line.
<BODY>
</BODY>
ANKIT SINGH 12
Formatting a Web Page
The content on a Web page needs to be attractive content of the Web page by using formatting tags.
<B>
<I>
<U>
<LI>
<BR>
<HR>
<B>
The <B> tag is used to bold font face.
<BODY>
</BODY>
<I>
The <I> tag is used to Italic font face.
<BODY>
</BODY>
ANKIT SINGH 13
<U>
The <U> tag is used to underline the text
<BODY>
</BODY>
<LI>
The <LI> tag is used to create a lists. In HTML Document represented with special set
of tags.
Ordered or Numbered list
Unordered or Bulleted list
Definition list
ANKIT SINGH 14
Unordered Or Bulleted List
Unordered or bulleted list represents a set of related items that do note follow a
specific order.
<BODY>
<ul><li>HTML </li>
<li>JAVA</li>
<li>C#</li></ul>
</BODY>
Definition list
The definition tag used one or more terms definition are to be included in an
HTML document. Its represent by the <DL> tag. And this tag to comprises two
other tags <DT> and <DD>
<BODY>
<DL>
<DT>Title1</DT><DD>This is a first definition</DD>
<DT>Title2</DT><DD>This is a second definition </DD>
</DL>
</BODY>
ANKIT SINGH 15
<BR>
The <BR> tag is used to break of the line code.
<BODY>
</BODY>
<HR>
The <HR> tag is used to create a horizontal line
<BODY>
</BODY>
ANKIT SINGH 16
Adding Images
The images are used to create more interesting as ideas are well
communication with images and graphics.
GIF:-
The Graphic Interchange Format The most commonly-use image format on
the web.
JPEG:-
Joint Photographic Experts Group The format is used when the image
is a photograph medical image or complex photographic
PNG:-
Portable Network Graphics The format is used an alternative to GIF
the PNG format a defines a portable well-compressed and well-
specified standard for bitmapped image files.
<BODY>
<IMG src=”ankit.jpg”></IMG>
</BODY>
ANKIT SINGH 17
Attributes for <image>
Alt The alt attribute is use to alternate text for an image this attribute
work only your image cannot display a browser.
ANKIT SINGH 18
Adding Navigation Links
The navigation links tag is using to link one page to another page using <A> tag
and attribute href or frame this attribute link image multimedia files to each
other.
href the href attribute specifies the URL to connect the document using
hyperlink
<A href=”Honepage.html”>Book Your course</A>
target the target attribute is use a browser windows you can refer to
another windows by using the target attribute
<A href=”Aboutus.html” target=”frame1”>About Us</A>
<AUDIO>
<VIDEO>
<AUDIO>
The <audio>tag provide adding a audio in a web page.
<VIDEO>
The <video> tag is provide displaying a video on a web page.
ANKIT SINGH 19
Measuring Data and Displaying a Progress
Bar
The progress bar is use to display a progress for downloading and uploading file
such as image video audio in disk space.
<METER>
<PROGRESS>
<METER>
The <meter> tag a scalar measurement within a used to display disk usage.
<P>Display a meter</p>
<PROGRESS>
The <progress> tag is used to display the progress of the task.
Progress of a task:
ANKIT SINGH 20
<PROGRESS value=”12” max=”100”></PROGRESS>
Semantic tags
<HGROUP>
<ARTICLE>
<ASIDE>
<HEADER>
<FOOTER>
<NAV>
<FIGURE>
<hgroup>
You need to group related heading and sub heading than you used to<hgroup>
tag.
<H6>shot Course</H6></HGROUP>
<ARTICLE>
The <ARTICLE> tag an independent or a self-contained content
ANKIT SINGH 21
<p>This Course is specifically designed to provide details about your
course</p></ARTICLE>
<ASIDE>
the <aside> tag is used the write a note or a tip
<HEADER>
The <HEADER> tag is used to defined website heading you can used multiple
<HEADER> tag.
<FOOTER>
The <FOOTER> tag is used to add a footer in your web page.
<NAV>
The <Nav> tag is used to group of link created by using <A> tag.
ANKIT SINGH 22
<NAV>
<A href=”Course”>Course</A>|
<A href=”Booking”>Booking</A></NAV>
<FIGURE>
The <FIGURE> tag is used to self-contained such as images diagrams photo.
<FIGURE><FIGCAPTION>HD Image</FIGCAPTION><IMG
src=”localimg.jpg” alt=”image” width”300” height=”400”></FIGURE>
ANKIT SINGH 23
Working With Style
The style of the web page depends upon look and feel of the HTML element use same
look and feel for all web pages you used to Cascading Style Sheet (CSS)
Inline style
Inline Style
Inline style is use to particular paragraph tags the Inline style are attached directly with
the HTML tag.
<HTML>
</HTML>
<html>
ANKIT SINGH 24
<head>
<style type=”text/css”>
P{color:red; font-size:20px; font-style:italic;}
</style>
</head>
<body>
<p>Welcome to the first internal style created by Ankit singh</p>
<p>compare to the other book</p>
</body>
</html>
P
{
color:red; font-size:20px; font-style:italic;
}
H1
{
color:blue;
}
Save the code mystyle.css
<html>
<head>
</head>
<body>
ANKIT SINGH 25
<h1>Welcome to the first internal style created by Ankit singh</h1>
</body>
</html>
CSS SELECTORS
To use a style any tag and you uniquely identified one than you can used CSS Selector
user defined CSS selectors ID and Class selector
<HTML>
<HEAD>
<STYLE>
P
{
color:red;
}
#pname
{
color:green;font-size:20px;font-weight:bold;
}
</STYLE>
ANKIT SINGH 26
</HEAD>
<BODY>
<p id=”pname”>Welcome to the HTML Book</p>
<p>Book Reading facility </p>
</BODY>
</HTML>
ANKIT SINGH 27
}
</style>
</head>
<body>
<h1>Welcome to the Ankit singh website</h1>
<h2>this site is very user friendly</h2>
<p>this site is gives information of all the HTML tag</p>
</body>
</html>
ANKIT SINGH 28
</html>
Font
Text
Link
List
Background
Font
Font properties is used to customize the text is display
P
{
Font-family: “Haettenschweiler”;
Font-size:20px;
}
h1
{
Font-variant:small-caps;
Font-style:italic;
}
Valid Values
PROPERTY Definition Sample Usage
ANKIT SINGH 29
Font-Family Is used to set the font Different font types,such {font-family: arial, times
type for a text. as times new roman, roman; }
courier, verdana,
Helvetica, arial, and san –
serif
Font-Style Is used to set the style for Normal, italic, or oblique { font – style : italic ; }
a text.
Font-Weight Specifies how the Normal or bolder decimal { font – weight : bold ;}
characters in a text values from 100 to 900 { font- weight : “ 600” ; }
should be displayed.
Text
Text properties Is used to change the colour alignment of text element.
P
{
letter-spacing:2px;
line-height:12px;
}
h1
{
color: red;
text-align: center;
}
ANKIT SINGH 30
text-align Is used to set the horizontal Left | right | Center {text – align : center; }
Alignment of the HTML | Justify
Element.
Color is used to set the color of A HEX value, on rgb {color: red ; }
text. Value, of a color name. {color: # 00ff00;}
color:rgb(0,0,255 ) ;
text-decoration Is used to specify the none | underline | {text-
decorations that can be over line | line- Decoration: underline;
added to a text through }
Link
ANKIT SINGH 31
Link properties is used to customize the link in the HTML document.
List
list properties is used to look of the order and unordered HTML lists.
Ul
{
list-style-type:square;
list-style-position: inside;
}
ANKIT SINGH 32
its-style-type Disk I circle I square { list – style-
I decimal I type: upper-
is used to specify the type Lower-roman | alpha. }
of the list-item markers. Upper-roman |
Lower-roman |
Upper-alpha |
Lower-Latin |
Upper-lain |none|
ist – style Sets all the properties in type || position || { list –style :
one declaration image Square outside
url (plus . gif ) ; }
Background
Background properties is used to specify the background color image of the HTML
element.
<style>
Body
{
Background-color:lavender;
}
</style>
Background Sets all the properties in Background – color \ (background : green url
one declaration. background - image ( ‘ img . gif ‘ ) } ;
Grouping Style
ANKIT SINGH 33
Style are uses to apply same style more than one selector by combining them.
H1,p
{
color:red;
}
Nesting Style
Nesting style used to style element inside the other element style this style used to
better look and feel.by using the class and ID selector.
Selector Example Description
Element1>element2 Div>p Select all the <p> elements, where <Div> is their immediate -
Parent element.
Element1 element2 Div p Select all the <p> elements inside the <Div> element.
Element1 + element Div+p Select the <p> element that is placed immediately after the <Div>
element.
Position
Float
Position
ANKIT SINGH 34
The position property is used to set the position an element on a web page.
Float
the float property is used to place the HTML element to left or right margin.
float: left | right | none
<html>
<head>
<style>
img
ANKIT SINGH 35
{
float:left;
}
.auto
{
clear:both;
}
</style>
</head>
<body>
<img src=”hotel1.jpg” height=”300” width=”500”></img>
Clear
The clear property is used to turn off the float effect on HTML element.
ANKIT SINGH 36
Applying Transitions
You want to change the color of the HTML element from red to black in the event is
mouse hover event the CSS transition provide a way to moderately change the HTML
element from one position to another.
<html>
<head>
<style>
Div
{
width:200px;
height:200px;
background:red;
-webkit-transition:width 4s;
-o-transition:width 4s;
}
div:hover
{
width:400px;
}
</style>
</head>
<body>
<div></div>
ANKIT SINGH 37
</body>
</html>
Applying Animations
To apply animation effects on HTML elements. You can create an animation that will
increase the size of the element when user clicks.
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
ANKIT SINGH 38
background-color: red;
-webkit-animation-name: example; /* Chrome, Safari, Opera */
-webkit-animation-duration: 4s; /* Chrome, Safari, Opera */
animation-name: example;
animation-duration: 4s;
}
/* Standard syntax */
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
Applying transformations
You want to rotate a cube having different pictures on its curves. CSS provides the
functionality of transformations to modify the HTML element.
2D transforms
2d transforms you can apply various transformations such as rotations or translations on
HTML element.
<html>
<head>
<style>
div
{
width:200px;
height:100px;
ANKIT SINGH 39
background-color:red;
transform:rotate(60deg);
-webkit-transform:rotate(60deg);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
3D
HTML element by using 3D transforms. The using transform methods
Project Time
Home style
ANKIT SINGH 40
aside p{text-align: center; background-color: darkgreen; color: white; font-
size: 15px; }
NAV a:hover{color:pink;}
Home.Html
<html>
<head>
<title>
UpComingMovies
ANKIT SINGH 41
</title>
</head>
</div>
</div>
<nav>
<A href="homepage.html">Home</A>|
<A href="aboutus.html">AboutUs</A>|
<A href="contactus.html">ContactUS</A>|
ANKIT SINGH 42
<A href="UpComingMovie.html">UpcomingMovies</A>|
<A href="Onlinebooking.html">OnlineBooking</A>
</nav>
</div>
<div style="width: 960px height: auto; position: relative; margin: 0px; padding: 29px;
overflow: hidden; background-color: white;">
<h4>Currently, showing...</h4>
<article>
We pioneered cinema halls in INDIA by establishing the first multiplex cinema in 2001 and
the largest 9-screen multiplex cinema in 2007.
With its head office in Los Angeles, ShowOnWheels is now serving the viewers of major us
cities.</p>
<p>Waiting in queues to book tickets for your favorite movie in now a matter of post.
ANKIT SINGH 43
enjoying a vacation at a Miami beach,partying in a discotheque, attending a confernce , or
taking Your pet for a walk, ShowOnWheels is there to reserve Your hot seat in your
favorite cinema.</p>
<aricle><br><br><br><br><br>
<details>
<ul>
<li>Los Angeles<li>Chicago<li>Houston</li><ul>
With an annual turnover of INDIA $12 million ShowOnWheels is expending its wings. We
are lanunching three new screens in South Africa, shortly.
The area most in flux in relation to the new media elements has to do with synchronized
media playback, multiple audio, video, and text tracks, and media element accessibility.
As to be expected, these areas also have the least implementation support.
A new addition to the HTML5 media elements is the new media controller object. This
object provides for synchronized playback among multiple audio and video elements
in a web page. When implemented, we should be able to play video and/or audio files
in multiple elements in the web page via one controller user interface.
Another new addition is support for multiple audio and video tracks within the media
resource. When this functionality is implemented, we should be able to pick from
among a list of audio tracks in different languages, play director commentary along
with the video, or enjoy picture-in-picture support.
There’s also browser support for multiple text tracks, too. Currently, browsers parse
the track element and it becomes part of the Document Object Model (DOM), but no
browser yet processes the track element’s contents and provides the caption or subtitle
text. Happily, though, there are JavaScript libraries that can process the captions or
subtitles within the track elements, giving us at least some interim functionality, as we’ll
see at the end of the chapter.
</details>
ANKIT SINGH 44
<h1><br>Hurry Heavy Discounts on weekend...</h1>
<aside>
<p>
<i><b>ShowOnWheels values its customers. We keep you updated with our new discounts
and offers.We appreciate your association!</b></i></p></aside>
</div>
</div>
</div>
</body>
</html>
ANKIT SINGH 45
ANKIT SINGH 46
Working with Tables and
Frames
Table are used for structuring and displaying complex information in a structuring format
on a web page.
Frames provide a mechanism for positioning and displaying several web pages in
different section of a single browser window.
Creating Tables
If you want to show the result information on your website than you need to creating a
well structured of table on a webpage using tables. Tables represent complex
information in a simple and easy to understand manner. By using tables
Creating Row
The Adding rows in the table using <tr> tag. The contents place between <tr>and </tr>
tag
Creating Columns
The adding the columns to the <td> tag the <td> tags are uses within <tr>
and </tr> tags.
<html>
<body>
<table border="2">
<tbody>
<tr><th>Name</th>
ANKIT SINGH 47
<th><ul>Login Id</th>
<th>Course Name</th>
<th>Marks</th></tr>
<tr class="alt"><td>steve</td>
<td>01234</td>
<td>My sql 5 Developer certified professional Exam,part I </td>
<td>92</td></td>
<tr><td>John</td>
<td>01235</td>
<td>Mysql 5 Developer Certified Professional Exam, part II</td>
<td>85</td>
<tr class="alt"><td>Joseph</td>
<td>01236</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, Part
I</td>
<td>98</td>
<tr ><td>Michel</td>
<td>01237</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, part
II</td>
<td>25</td>
</tr>
</tbody>
</body>
</html>
ANKIT SINGH 48
Combining Multiple Rows and Columns into a Single cell
That only the column of the first row should extend to four columns and display
the heading Top Three performers. The remaining rows of the table should
have four separate columns.
<html>
<body>
<table border="2">
<tbody>
<tr><th colspan="4"><center>Top Three
Performers</center></th></tr>
<tr><th>Name</th>
<th><ul>Login Id</th>
<th>Coutse Name</th>
<th>Marks</th></tr>
<tr class="alt"><td>steve</td>
<td>01234</td>
<td>My sql 5 Developer certified professional Exam,part I </td>
<td>92</td></td>
<tr><td>John</td>
<td>01235</td>
<td>Mysql 5 Developer Certified Professional Exam, part II</td>
<td>85</td>
<tr class="alt"><td>Joseph</td>
<td>01236</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, Part
I</td>
<td>98</td>
<tr ><td>Michel</td>
<td>01237</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, part
II</td>
<td>25</td>
</tr>
ANKIT SINGH 49
</tbody>
</body>
</html>
Rowspan Example:
<html>
<body>
<table border="2">
<tbody>
<tr><th rowspan="6"><center>Top Three
Performers</center></th></tr>
<tr><th>Name</th>
<th><ul>Login Id</th>
<th>Coutse Name</th>
<th>Marks</th></tr>
<tr class="alt"><td>steve</td>
<td>01234</td>
<td>My sql 5 Developer certified professional Exam,part I </td>
<td>92</td></td>
<tr><td>John</td>
<td>01235</td>
<td>Mysql 5 Developer Certified Professional Exam, part II</td>
ANKIT SINGH 50
<td>85</td>
<tr class="alt"><td>Joseph</td>
<td>01236</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, Part
I</td>
<td>98</td>
<tr ><td>Michel</td>
<td>01237</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, part
II</td>
<td>25</td>
</tr>
</tbody>
</body>
</html>
The users to understand the information that the table display for creating a
table title the using the <caption> closing tag </caption
<html>
<body>
<table border="2">
<caption>Test Results</caption>
ANKIT SINGH 51
<tr><th rowspan="6"><center>Top Three
Performers</center></th></tr>
<tr><th>Name</th>
<th><ul>Login Id</th>
<th>Coutse Name</th>
<th>Marks</th></tr>
<tr class="alt"><td>steve</td>
<td>01234</td>
<td>My sql 5 Developer certified professional Exam,part I </td>
<td>92</td></td>
<tr><td>John</td>
<td>01235</td>
<td>Mysql 5 Developer Certified Professional Exam, part II</td>
<td>85</td>
<tr class="alt"><td>Joseph</td>
<td>01236</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, Part
I</td>
<td>98</td>
<tr ><td>Michel</td>
<td>01237</td>
<td>Mysql 5 Database Administrator Certified Professional Exam, part
II</td>
<td>25</td>
</tr>
</body>
</html>
ANKIT SINGH 52
<html>
<head>
<style>
th
{
font-size:18px;
text-align:center;
padding-top:3px;
background-color:#BDB76B;
color:#006400;
}
caption
{
font-size:35px;
color:black;
}
td
{
font-size:15px;
border:1px solid #008B8B;
padding:3px;
background-color:khaki;
ANKIT SINGH 53
}
tr.alt td
{
color:#F0E68C;
background-color:#B22222;
}
</style>
</head>
<body>
<table border="2">
<caption>Test Results</caption>
ANKIT SINGH 54
<td>Mysql 5 Database Administrator Certified Professional Exam, part
II</td>
<td>25</td>
</tr>
</body>
</html>
ANKIT SINGH 55
ANKIT SINGH 56
ANKIT SINGH 57
Accessing Multiple Web Page Using Frames
Which makes it look like a single page. This is made possible by using the
concept of frames. A frame is a rectangular region in a browser window.
The first frame that is named as HeaderFrame display the name of the website.
The second frame that is named as NavigationFrame contains the links to the
various MySQL courses. The third frame that is named as ContentFrame display
the web page.
Home.HTML page
<html>
<body>
ANKIT SINGH 58
<iframe src="head nav.html" name="headerframe"
width="100%"height="135"></iframe>
<iframe align="right"
name="contentFrame"width="74%"height="500"></iframe>
</body>
</html>
NAV.HTML
<html>
<head>
<style>
body
{background-color:#00C0F3;}
ul{margin:0;padding:0;list-style:none;width:320px;}
a:hover{background-color:#5E9DC9;}
</style>
</head>
<body>
<li><a href="">ASP.NET</a></li><ul>
</body>
ANKIT SINGH 59
</html>
HEAD NAV.HTML
<html>
<head>
<style>
body
{background-color:#00C0F3;}
h1{color:white;font-size:45;}
</style>
</head>
<body>
<center>
</body>
</html>
ANKIT SINGH 60
ANKIT SINGH 61
Project Time
Home style
ANKIT SINGH 62
aside p{text-align: center; background-color: darkgreen; color: white;
font-size: 15px; }
NAV a:hover{color:pink;}
ANKIT SINGH 63
NAV A{text-decoration: none; color: white;}
Ucm style
<style>
tr{color:green}
</style>
Ucm.HTML
<html>
<head>
<title>
UpComingMovies
</title>
<script type="text/javascript">
function onlinebooking()
ANKIT SINGH 64
alert("The Bookings for the Upcoming Movies are not Currently
Available");
}</script>
</head>
<body><body><div style="position:
relative;width:150px;height:auto;padding-top:100px; float:left;">
</div>
</div>
<nav>
<A href="homepage.html">Home</A>|
<A href="aboutus.html">AboutUs</A>|
<A href="contactus.html">ContactUS</A>|
<A href="UpComingMovie.html">UpcomingMovies</A>|
<A href="Onlinebooking.html">OnlineBooking</A>
</nav>
ANKIT SINGH 65
</div>
<h4><b><i><center>UpcomingMovies</center></i></b><h4>
<table><tr><th>Movie Category</th>
<th>Movie Title</th>
<th colspan="3">starring</th>
<th>Director</th>
<th>Release Date</th>
<th>Certificate</th>
<th>Online Bookings</th></tr>
<tr>
<td rowspan="2">Thriller</td>
<td>Jennifer Lawrence</td>
<td>Patrick</td>
<td>Evan</td>
<td>Freddie Highmoree</td>
<td>12 Jan,2015</td>
<td>INDIA</td>
<tr><td>prisoners</td>
<td>Rachel Wood</td>
<td></td>
<td>Victoria A.</td>
ANKIT SINGH 66
<td>19 Jan,2015</td>
<td>INDIA</td>
<td><a href="">BookYourShow</a></td></tr>
<tr><td rowspan="3">Romantic</td>
<td>Ellen page</td>
<td>Rechel Wood</td>
<td>Victoria</td>
<td>Freddie Highmoree</td>
<td>india</td>
<td><a href="">BookYourShow</a></td></tr>
<tr><td>Twilight Saga</td>
<td>patrick</td>
<td>Wood A.Han</td>
<td>Victoria</td>
<td>Victoria A.</td>
<td>17 May,2015</td>
<td>india</td>
<td><a href="">bookyourshow</a></td></tr>
<tr><td>if only_ii</td>
<td>Ellina smith</td>
<td>Rachel Wood</td>
<td></td>
<td>Robert vann</td>
<td>a</td>
<td><a href="">bookyourshow</a></td></tr>
ANKIT SINGH 67
<tr><td rowspan="4">Action</td>
<td>star wars</td>
<td>robert</td>
<td>logan lerman</td>
<td></td>
<td>ariana grande</td>
<td>india</td>
<td><a href="">bookyourshow</a></td></tr>
<tr><td>man of steel</td>
<td>patrick</td>
<td>rachel wood</td>
<td></td>
<td>victoria</td>
<td>17 may,2015</td>
<td>india</td>
<td><a href="">bookyourshow<a></td></tr>
<tr><td>area 52</td>
<td>dianna</td>
<td>alice</td>
<td></td>
<td>robert s. vann</td>
<td>a</td>
<td><a href="">bookyourshow</a></td></tr>
<tr><td>2 guns</td>
<td>illiana</td>
<td>john park</td>
ANKIT SINGH 68
<td>ankit</td>
<td>josh hutcherson</td>
<td>india</td>
<td><a href="">bookyourshow</a></td></tr></table></div>
</body>
</html>
ANKIT SINGH 69
ANKIT SINGH 70
Scripting
Types of Scripting
Create a dynamic and interactive web page you need to incorporate a block of code the
script can be executed either by the web browser. The requests is send to a computer
that is placed at a different location on the World Wide Web. Computer on which the
browser is running is known as the client.
Client-side scripting
Server-side scripting
Client-side Scripting
Client side scripting refers to the scripts that are executed at the client side by the web
browser running on the user’s computer some of the languages used for creating client
side scripts are client side JavaScript (CSJS)
Server-side Scripting
Server-side scripting refers to the scripts that are executed by the web server on the
basis of the user’s request. Some of the languages used for creating server-side scripting
are server-side JavaScript (SSJS)
ANKIT SINGH 71
Benefits of javaScript
Manipulate cookies java script can be used to access and store user
information such as client preferences and authentication information of a client
computer in the form of cookies.
Implementing JavaScript
JavaScript is one of the most popular scripting languages. It can be used to provide
functionality to a web page.
A script can be embedded directly into a web page by writing the javaScript code inside
the <script> tag. Or writing the JavaScript code in an external JavaScript (.js) file.
<html>
<body>
<SCRIPT type=”text/javascript”>
alert(‘Welcome to JavaScript’);
</SCRIPT>
</body>
</html>
<html>
ANKIT SINGH 72
<body>
<h1>By Products</h1>
</SCRIPT>
</body>
</html>
Defining Variables
Quantity=5
Price=250
Declaring a variable
The using a variable in your program you should declare it first. JavaScript allow to
declare a variable by using the var keyword.
var var_name;
var employeeName ;
ANKIT SINGH 73
Initializing a variable without declaring it
var employeeName;
employeeName=”Peter”;
var employeeName=”peter”;
employeeName=”peter”;
using Operators
<html>
<body>
<SCRIPT type=”text/javascript”>
var employeeName;
var basicSalary;
var othersAllowance;
var TotalSalary;
employeeName=”peter”;
basicSalary=20000;
otherallowance=1000;
TotalSalary=basicSalary+otherAllowance;
</SCRIPT>
</body>
</html>
ANKIT SINGH 74
Operator Categories
Arithmetic Operators
Assignment Operator
Comparison Operators
Logical Operators
Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations on variable and literals.
Assignment Operator
ANKIT SINGH 75
An assignment operator (=) is used to assign a value or a result of an expression to a
variable.
Arithmetic assignment operators are used to perform arithmetic operations and assign
the value to the variable a the left side of the operator
Comparison Operators
Comparison operators are used to compare two value and perform an action on the basis
of the comparison.
ANKIT SINGH 76
Logical Operators
Logical operators are used to evaluate complex expressions in which there is a need to
evaluate a single expression or multiple expressions to assess the result.
Conditional Constructs
ANKIT SINGH 77
The if statement in the if…else conditional construct is followed by a logical expression in
parenthesis.
If(exp.)
//statements;
Else
//statements;
Example
var age=5;
if(age<12)
Else
switch(variableName)
case ConstantExpression_1 :
//statement;
break;
ANKIT SINGH 78
case ConstantExpression_2 :
//statements;
break;
case ConstantExpression_n:
//statements;
break;
default:
//statements;
break;
Loop Constructs
while(expression)
statements;
Example
<SCRIPT type=”text/javascript”>
var num=0;
while(num<20)
ANKIT SINGH 79
</SCRIPT>
The do while loop is similar to the while loop but do while loop execute at least one time
do
{ statements;}
while(condition);
Example
<SCRIPT type=”text/javascript”>
var num=0;
do
{num=num+1;
alert (num);
while(num<20)
</SCRIPT>
ANKIT SINGH 80
The for Loop
The for loop allow the execution of a block of code depending on the result of the
evaluation of the text condition.
//code block
<SCRIPT type=”text/javascript”>
var num;
ANKIT SINGH 81
var sum=0;
for(num=100;num<200;num++)
Sum=sum+num;
alert(sum);
</SCRIPT>
Break
while(test condition)
//statement1;
if(test condition1)
break;
//statement2;
//statement3;
Continue
The continue statement is used to skip all the subsequent instruction and take the
control back to the beginning of the loop.
while(test condition)
//statement1;
if(test condition1)
ANKIT SINGH 82
continue;
//statement2;
//statement3;
Function
Built-in functions
User-defined functions
Built-in Functions
Built-in function are ready to use as they are already coded the built-in functions
supported by JavaScript.
isNaN ()
parseInt ()
parseFloat ()
evel ()
prompt ()
confirm ()
isNaN ()
the isNaN function determines whether a parameter is not a number. The function return
true if the parameter is not a number
<html>
<body>
<SCRIPT type="text/javascript">
num1="Two thousant";num2=8000;
Result=isNaN(num1);alert(Result);
res=isNaN(num2); alert(res);
</SCRIPT>
ANKIT SINGH 83
</body>
</html>
parseInt ()
the parseInt () function parse the string parameter and return the corresponding integer.
X=”5”;
Y=parseInt(x);
parseFloat ()
the parseFloat () function takes a string parameter and returns a floating point number.
X=”6.5”;
y=parseFloat(x);
eval()
<SCRIPT type=”text/javascript”>
alert(res1);
</SCRIPT>
prompt ()
the prompt () function is used to display a prompt dialog box allow a user to input value.
<html>
<body>
<script>
var a,b,c;
c=a+b;
ANKIT SINGH 84
document.write(c);
</script>
</body>
</html>
confirm ()
the confirm () function is used to display a dialog box that will enable a user to verify or
accept a task. If user clicks the ok button the confirm () function return true. If the user
clicks the cancel button the confirm () function return false.
<html>
<body>
<SCRIPT type="text/javascript">
var response;
if(response==true)
else
</SCRIPT>
</body>
</html>
User-defined Functions
The user-defined function you to define your own function according to your needs.
Creating Functions
ANKIT SINGH 85
function functionName (variable1,variable2)
//function statement
Calling a Function
functionName ();
Function functionName()
var variable=10;
return variable;
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
function myFunction(a, b) {
return a * b;
</script>
</body>
</html>
ANKIT SINGH 86
ANKIT SINGH 87
Creating Forms
The data entered using these form elements needs to be processed further upon
submission. Every web page should respond to end user actions such as clicking
a submit button.
Customers to place online order with various details such as the name contact
number and address in an online form named as Order Food Online.
Create Form
If you create a form on a web page you need to <form> tag. The <form>
Tag is define a form has on opening <form> tag and closing </form> tag.
Name
Id
Action
Method
Autocomplete
Novalidate
Target
Name
ID
ANKIT SINGH 88
The ID attribute is used to uniquely identify a form element on a web page.
Action
The action attribute is used to the URL of the document assumed as the location
for the form submission.
Method
The method attribute is used to be submitted to the file or the URL action
attribute.
Get
Post
Get
The get value form data to the URL of the form submission. The size of data that
can be submitted using the get method.
Post
The post value dose not append the form data to the URL of the form submitted.
A large amount of data can be sent using the post method.
Autocomplete
Novalidate
The novalidate attribute that the date in the form should not be validate by the
browser.
Target
the target attribute is used to the name of thee frame or the window in which
response after submission.
ANKIT SINGH 89
_blank: the response should be displayed in a new frame or
windows.
Form Elements
<INPUT>
<SELECT>
<LABEL>
<FIELDSET>
<TEXTAREA>
<DATALIST>
<KEYGEN>
<OUTPUT>
<BUTTON
<INPUT>
The <INPUT> tag. Is used to input inside A form the input fields are various type
such as text box radio button or check box. Some important attributes type
value name ID autocomplete autofocus form required pattern and placeholder.
Type
The type attribute is defined the type of input field to be added on the form.
ANKIT SINGH 90
Text creates a single line text field. Type attribute is text two
additional attribute size and maxlength, the size attribute is used for
limiting the character. The maxlength attribute is defined the maximum
number of characters.
Password
The password field which will not display the characters being typed by the user.
Actual show the values for each character ****.
Radio
A radio button used to select one of the options from a set of given options.
Checkbox
A checkbox is used to select one or more option from a set of given options.
ANKIT SINGH 91
<input type=”checkbox” name=”Cuisine1” value=”Continental Cuisine”>
Continental Cuisine <input type=”checkbox” name=”Cuisine2” value=”Chinese
Cuisine”> Chinese Cuisine
Submit
A submit button is used to the form data submit to the specified location using
action attribute of the form.
Formaction
It is used to a URL the form data would be submitted the submit button is
clicked.
Formmethod
It is used to the method such as get and post the form data will be sent to the
file or URL in the action attribute of the form
Reset
A reset button clears the values entered by a user in the form fields.
URL
That is used to enter a URL of a website the value in this field is automatically
validated the form is submitted.
ANKIT SINGH 92
A field in an HTML form to accept the email address from the users.
Range
Date
Time
Number
ANKIT SINGH 93
Is used to create an input field for entering a numeric value.
Tel
Image
Is used an image to be used as a submit button. The value of the type attribute
is image
Required attribute
The required attribute is used an input field must not be left empty while
submitting the form.
Placeholder
Is used to a simple value for the input filed that will be displayed until the user
enters a value
ANKIT SINGH 94
Select Tag
The select tag is a container tag it create a drop-down list in the form.
Option Tag
It is always used within the <select> tag. Option tag is used to create a list of
option in the drop-down list.
Optgroup Tag
Label
For is used to bind the <label> tag with the input field same value
as the Id attribute
Textarea
ANKIT SINGH 95
Text area tag is used the user can enter a large amount of text.
Rows set the number of row of text that will be visible without
scrolling up or down in the field
Cols set the number of columns of text that will be visible without
scrolling right or left in the field.
Datalist
The datalist tag is used to create a pre-defined options for an input fields.
<datalist id="browsers">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<html>
<head>
<style>
ANKIT SINGH 96
body
background-color:#FFEBCD;
.autostyle
color:red;
font-size:20px;
text-align:center;
</style>
</head>
<body>
<table>
<tr class="autostyle">
<td colspan="2">OrderFoodOnline</td></tr>
<tr><td><label for="name">Name:</lable></td>
<tr>
<td><label for="date">Date:</label></td>
ANKIT SINGH 97
Required></td></tr>
<tr>
required></td></tr>
<label for="veg">Vegetarian</label>
<tr>
<td><select>
<option value="opt3">Benihana</option>
<option value="opt4">Gallipoli</option>
<tr><td><label for="drinks">Drinks:</label></td><td>
<select>
<option value="opt7">Caffelatte</option>
<option value="opt8">Cappuccino</option>
</select></td></tr>
<tr><td><label for="soups">Soups:</label></td>
ANKIT SINGH 98
<td><select><option value="opt9">Select Your Soup of Your
Choice</option>
<option value="opt10">Minestrone</option>
<option value="opt11">Fonduta</option>
<tr><td><label for="dishes">Dishes:</label></td><td>
<optgroup label="Italian">
<option value="opt14">Pasta</option>
<option value="opt15">Fish</option>
<option value="opt16">Rice</option>
</optgroup>
<optgroup label="Chinese">
<option value="opt17">Chowmin</option>
<option value="opt18">Manchurian</option>
<tr><td><label for="orderfor">Address:</label></td>
<tr><td><label for="State">State:</label>
</td><td>
ANKIT SINGH 99
<datalist id="state">
<option value="Alabama">
<option value="California">
<option value="Delaware">
<option value="Florida">
<option value="Hawaii"></datalist><br>
</td></tr>
</table>
</form>
</body>
</html>
Output
Form the name of one or more forms to which the output tag
belongs.
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">
</form>
Button
Is used to create a button input type submit.
Type is used to accept the value such as button submit and reset
<html>
<head>
<style>
#button{margin-left:50px;}
...</style>
</head>
<body>
...</tr>
<tr><td>
</body>
</html>
A web page is displayed in a browser a user can access information not only
about the current page but also additional details such as information about
window and screen the pages the user has visited in the past or the version the
browser begin used to view the document.
Window
Document
Navigator
Screen
History
Location
Browser object represent the browser environment and provide properties and
methods for its access and manipulation.
The window object is one of the highest level objects in the javaScript Object
hierarchy. It represents a browser window which display the document.
Function open_win()
(“hotelBooking.html”,”height=100 ,width=200”)
<html>
<head>
<SCRIPT type="text/javascript">
function clockTime()
var hrs=todayDate.getHours();
var mns=todayDate.getMinutes();
var scs=todayDate.getSeconds();
mns=check(mns);
scs=check(scs);
document.getElementById('displayTime').innerHTML=hrs+":"+mns+":"
+scs;
t=setTimeout('clockTime()',1000);
function check(t)
if(t<10)
t="0"+t;
return t;
</head>
<BODY onload="clockTime()">
<DIV ID="displayTime"></DIV>
</BODY>
</html>
The document object model hierarchy. The document object provides the
properties and methods to work with many aspects of the current document
including information about forms links title current location and URL.
Write()
Writeln()
getElementsByName()
getElementsByTagName()
getElenmentsById()
Document.write(“Hello”);
<html>
<head>
<style>
Body
Background-color:#DAA520;
</style>
</head>
<body>
<SCRIPT type="text/javascript">
name","");
document.write("<p>");
document.write("<i>");
document.write("<b>");
document.write("Welcome "+name);
document.write("</p>");
document.write("</i>");
document.write("</b>");
</SCRIPT>
</html>
Writeln
The writeln() method also writes text on a web page. The only difference is that
the writeln() method appends a new line character at the end of the text.
<html>
<body>
<PRE>
<SCRIPT type="text/javascript">
document.writeln("Hi !");
document.write("Have a ");
document.write("great day");
</SCRIPT>
</PRE>
</body>
</html>
getElementsByName
document.getElementsByName(“name_of_the_element”);
<html>
<SCRIPT type=”text/javascript”>
function count()
var x=document.getElementsByName(“link”);
</SCRIPT>
<body>
</body>
</html>
getElementsByTagName
A user can customize the background color of all text boxes on a web page a
drop down list is used to choose the background color. If the user selects the
green color from a drop down list the background color of all the text boxes in
the document changes to green.
document.getElementsByTagName(“tag_name”);
var x=document.getElementsByTagName(“a”);
alert(x.length +” Hyperlinks”);
HTML element used on a web page has an optional attribute ID which uniquely
identifies the element the document.getElementById() method
document.getElementById(“id_of_the_element”);
<html>
<SCRITP type=”text/javascript”>
function replacetext()
}</SCRIPT>
<body>
</body>
</html>
Handling Events
<head>
<title>registration details</title>
<style>
h1,h3{
color:black;
font-size:40px;
text-align:center;
table{
margin-left:550px;
background-color:gray;
td{
padding:10px;
#button{
margin-left:670px;}
<SCRIPT>
function show()
var fname=document.getElementById
("textbox1").value;
var lname=document.getElementById
("textbox2").value;
var age=document.getElementById
("age").value;
var address=document.getElementById
("address").value;
var gender=document.getElementById
("gender").value;
function changecolor(val)
if ((val.value=="")||(val.value==null))
val.style.background="pink";
else
val.style.background="yellow";
</SCRIPT>
</head>
<body>
<table>
<tr>
</tr><tr>
<td>last name:</td>
</tr><tr>
<td>age:</td>
</tr><tr>
</tr><tr>
</tr><tr>
</tr></table>
</html>
You can handle user actions or event handlers. To handle each and vary user
action or event a listener is notified.
addEventListener()
addEventListener(type,listener[,useCapture]);
<html>
<head>
<SCRIPT type="text/javascript">
function OnClick ()
function AddEventHandler()
if(Button.addEventListener)
Button.addEventListener("click",OnClick,false);
function RemoveEventHandler ()
var Button=document.getElementById("Button");
if(Button.removeEventListener)
Button.removeEventListener("click",OnClick,false);
</SCRIPT>
</head>
<body>
Click on the Submit button when the "click" event has a listener and
when it does not.<br>
<button id="Button">Submit</button>
</body>
The navigator object is one of the top level objects in the javaScript object the
navigator object is an independent object the own set of properties and method.
<body>
<SCRIPT type="text/javascript">
document.write(navigator.appName);
document.write(navigator.appVersion);
</SCRIPT>
</body>
</html>
The screen object enable you to access details of the user’s screen such as its
width, height, and resolution.
<body>
<SCRIPT type="text/javascript">
document.write("Height: "+screen.availHeight);
document.write("Width: "+screen.availWidth);
</SCRIPT>
</html>
The history object contains a list of all the page that have been visited by user.
<html>
<head>
<SCRIPT type="text/javascript">
function show()
alert(history.length);
</SCRIPT>
</head>
<body>
</body>
</html>
The location object contains information about the current URL it can also be
used to enable navigator to different URLs on the internet.
Protocol://hostname:port/pathname/search#hash
port: the port number of the URL it is optional. If the port number
is not specified for the http request.
search: the search string which is any portion of the URL. Followed
by a question mark such as
http://www.silvertech.com/careers.html/search? Programmer.
</form>
Form
Button
Checkbox
Text
Textarea
Radio
Select
Form
A form accepts user inputs. When a web page containing multiple forms is
viewed in a browser
reset() reset all the fields of the given form syntax is used for the
reset() method form1.reset()
Onreset: Occurs a user opts for resetting the fields of the form by
clicking the reset button or hyperlink
Button
The button object refers to the HTML button. It allows you to perform several
tasks based on user action.
Checkbox
click()
focus()
blur()
document.form1.checkbox1
<html>
<head>
Body
Background-color:pink;
</style>
<SCRIPT>
function validate()
If(document.f1.check1.checked==false)
return false
else
return turn
</SCRIPT>
</head>
<body>
</form>
</body>
</html>
onchange: fired after the occurrence of the blur event when the
value of the text object.
onselect: fired when the user selects a part of the text within the
text field. Document.form1.text1
Textarea
The textarea object refers to the HTML textarea the textarea object has similar
method and event attribute
Radio
Document.form1.radio1
<html>
<head>
<style>
Body
Background-color:pink;
</style>
<SCRIPT>
function validate()
if((document.f1.M.checked==false)&&(document.f1.F.checked==false))
return false
else
return true
</SCRIPT>
</head>
<body>
Gender:
</form>
</body>
</html>
Select
blur()
focus ()
onfocus
onblur
document.form1.select1
<html>
<head>
<SCRIPT>
function validate()
if(document.f1.opt.value==0)
return false
else
return true
</SCRIPT>
</head>
<body>
Country:
<option value=”1”>India</option>
<option value=”3”>UKs</option>
</select>
</form>
</body>
</html>
Canvas provides an easy and powerful way to create graphic on a web page. A canvas
has on content of its own. A canvas is simply an area on a web page that act as a
container for embedding graphic objects.
A canvas is defined by using the <canvas> tag. This tag is defined in the body section of
the HTML Document.
<SCRIPT>
var c=document.getElementById(“myCanvas”);
var ctx=c.getContext(“2d”);
</SCRIPT>
You can draw shapes such as rectangle and square on it rectangle and square are the
easiest shapes to draw on the canvas element by using the javascript function.
rect ()
fillRect ()
strokeRect ()
clearRect ()
rect()
the rect() method is used to create a rectangle on the canvas the default color of the
canvas to draw the outline of the rectangle.
rect(X,Y,width,height);
<html>
<body>
<SCRIPT>
var ctx=c.getContext("2d");
ctx.rect(30,30,120,120);
ctx.stroke();
</SCRIPT>
</body>
</html>
fillRet()
the fillRect () method is used to create a rectangle filled with the specified color. The
default color is black.
fillRect(X,Y,width,height);
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
</SCRIPT>
</body>
</html>
strokeRect()
create a rectangle using by the rect() method you also need to use the stroke() method
to define its outline on the canvas.
strokeRect(X,Y,width,height);
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.strokeRect(30,30,120,120);
</SCRIPT>
</body>
</html>
the clearRect() method is used to clear a portion of the rectangle it clears the
specified pixels within the given rectangle.
clearRect(X,Y,width,height);
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillRect(30,30,120,120);
ctx.clearRect(50,50,40,40);
</SCRIPT>
</body>
</html>
The graphic objects on a canvas by using the default stroke and fill color. You can use
colors other than the default color for creating th graphic object.
fillStyle
strikeStyle
shadowcolor
fillStyle
the fillStyle property is used to define a color that will be used to fill any closed shape
drawn on the canvas.
fillStyle=”color”;
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
</SCRIPT>
</body>
</html>
strokeStyle
the strokeStyle property is used to set the outline color of a shape drawn on the canvas
strokeStyle=”color”;
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.strokeStyle="blue";
ctx.strokeRect(30,30,120,120);
</SCRIPT>
</body>
shadowColor
you have drawn a shape on the canvas you may want to make it more it more stylish by
creating a shadow on it to graphic object on the canvas
shadowColor=”color”;
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.shadowBlur=40;
ctx.fillStyle="pink";
ctx.shadowColor="black";
ctx.fillRect(30,30,120,120);
ctx.shadowColor="blue";
ctx.fillRect(170,30,120,120);
</SCRIPT>
</html>
Creating simple shapes on the canvas you can also apply style such as gradients.
addColorStop()
createLinearGradient()
createRadialGradient()
createPattern()
addColorStop()
to create gradients you need to first specify the colors and their position in a gradient
object.
addColorStop(position,color);
createLinearGradient(X0,Y0,X1,Y1);
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var grad=ctx.createLinearGradient(0,0,170,0);
grad.addColorStop(0,"blue");
grad.addColorStop("0.5","yellow");
grad.addColorStop(1,"red");
ctx.fillStyle=grad;
ctx.fillRect(20,20,180,180);
</SCRIPT>
</body>
</html>
createRadialGradient(X0,Y0,R0,X1,Y1,R1);
Y0 the y-coordinate of the start point of the gradient (x0,y0) the center
Y1 the y-coordinate of the end point of the gradient (x1,y1) the center
R1 the radiu of the ending circle creating the radial gradient object.
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var grad=ctx.createRadialGradient(75,50,5,90,60,100);
grad.addColorStop("0.5","yellow");
grad.addColorStop(1,"red");
ctx.fillStyle=grad;
ctx.fillRect(20,20,180,180);
</SCRIPT>
</body>
</html>
createPattern()
createPattern(img,”repeat|repeat-x|repeart-y|norepeat”);
<body>
<button onclick="draw('repeat')">Repeat</button>
<SCRIPT>
function draw(direction)
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var img=document.getElementById("pattern");
var pat=ctx.createPattern(img,direction);
ctx.rect(0,0,300,300);
ctx.fillStyle=pat;
ctx.fill();
</SCRIPT>
</body>
</html>
A path ia a series of points joined together to create lines or shapes. In canvas you can
use line or paths to draw shapes other than rectangles or squares.
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(40,40);
ctx.lineTo(240,40);
ctx.stroke();
</SCRIPT>
</body>
</html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.arc(80,90,50,0,Math.PI*2,false);
ctx.closePath();
ctx.fillStyle="yellow";
ctx.fill();
</SCRIPT>
</body>
</html>
bezierCurveTo()
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
ctx.beginPath();
ctx.moveTo(200,20);
ctx.bezierCurveTo(80,20,80,100,150,100);
ctx.stroke();
</SCRIPT>
</body>
</html>
To drawing shapes or lines on the canvas you can also draw text on it
fillText()
fillText(text,x,y,width);
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="15px Georgia";
ctx.fillText("Fill Text",10,60,120);
ctx.font="15x Verdana";
var gradient=ctx.createLinearGradient(0,0,170,0);
gradient.addColorStop("0","magenta");
gradient.addColorStop("0.5","blue");
gradient.addColorStop("1","red");
ctx.fillStyle=gradient;
</SCRIPT>
</body>
</html>
the strokeText() method is used to draw a text at the specified position on the canvas by
using the current font style and color.
strokeText(text,x,y,width);
<html>
<body>
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="15px Georgia";
ctx.strokeText("Fill Text",10,60,120);
ctx.font="15x Verdana";
var gradient=ctx.createLinearGradient(0,0,170,0);
gradient.addColorStop("0.5","blue");
gradient.addColorStop("1","red");
ctx.strokeStyle=gradient;
</SCRIPT>
</body>
</html>
drawImage(img,x,y);
drawImage(img,x,y,width,height);
drawImagw(img,sx,sy,swidth,sheight,x,y,width,height);
<html>
<body onload=setImage()>
<SCRIPT>
function setImage()
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
img.src="a.jpg"
img.onload=function()
ctx.drawImage(img,10,10,150,150);
</SCRIPT>
</body>
</html>
If you want to create a bar graph on a web page than you need to download the
RGraph.common.core.js and RGraph.bar.js files.
you can move HTML element from one position to another position easily while working
with a canvas you may want to shift the graphics object from one position to another
and increase or decrease their size.
translate()
scale()
rotate()
translate
the translate () method is used to reset the origin of the canvas to the specified position.
translate(x,y);
var c=document.getElementById(“myCanvas”);
var ctx=c.getContext(“2d”);
ctx.fillStyle=”red”;
ctx.fillRect(10,10,100,100);
<html>
<body >
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(10,10,100,100);
ctx.translate(50,25);
ctx.fillStyle="blue";
ctx.fillRect(10,10,100,100);
</SCRIPT>
</body>
Scale
The scale () method is used to increase or decrease the units in the canvas grid.
scale(scalewidth,scaleheight);
<html>
<body >
<SCRIPT>
var c =document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.translate(50,25);
ctx.scale(2,2);
ctx.fillStyle="blue";
ctx.fillRect(10,10,100,100);
</SCRIPT>
</body>
</html>
Rotate
The rotate() method is used to rotate the graphic object to a degree in the clockwise
direction
rotate(angle);
<html>
<body >
<SCRIPT>
var c =document.getElementById("myCanvas");
ctx.fillStyle="red";
ctx.fillRect(10,10,100,100);
ctx.rotate(25);
ctx.fillStyle="blue";
ctx.fillRect(40,40,100,100);
</SCRIPT>
</body>
</html>
<html>
<head>
</head>
</CANVAS>
<SCRIPT type="text/javascript">
var canvas;
var ctx;
var x = 390;
var y = 290;
var dx = 2;
var dy = 2;
function circle() {
ctx.beginPath();
ctx.fillStyle="red";
ctx.arc(x,y,10,0,Math.PI*2,true);
ctx.fill();
ctx.closePath();
function clear() {
function init() {
canvas = document.getElementById
("canvas");
ctx = canvas.getContext("2d");
function draw() {
clear();
circle();
dx = -dx;
dy = -dy;
x += dx;
y += dy;
init();
</SCRIPT>
</BODY>
</html>
<!DOCTYPE html>
<html>
<body>
</canvas>
<script>
ctx.translate(radius, radius);
setInterval(drawClock, 1000);
function drawClock() {
drawFace(ctx, radius);
drawNumbers(ctx, radius);
drawTime(ctx, radius);
var grad;
ctx.beginPath();
ctx.fillStyle = 'pink';
grad.addColorStop(0, '#333');
grad.addColorStop(0.5, 'white');
grad.addColorStop(1, '#333');
ctx.strokeStyle = grad;
ctx.lineWidth = radius*0.1;
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = '#333';
ctx.fill();
var ang;
var num;
ctx.textBaseline="middle";
ctx.textAlign="center";
ctx.rotate(ang);
ctx.translate(0, -radius*0.85);
ctx.rotate(-ang);
ctx.fillText(num.toString(), 0, 0);
ctx.rotate(ang);
ctx.translate(0, radius*0.85);
ctx.rotate(-ang);
//hour
hour=hour%12;
hour=(hour*Math.PI/6)+
(minute*Math.PI/(6*60))+
(second*Math.PI/(360*60));
//minute
minute=(minute*Math.PI/30)+(second*Math.PI/(30*60));
// second
second=(second*Math.PI/30);
ctx.beginPath();
ctx.lineWidth = width;
ctx.lineCap = "round";
ctx.moveTo(0,0);
ctx.rotate(pos);
ctx.lineTo(0, -length);
ctx.rotate(-pos);
</script>
</body>
</html>
Implementing Geolocation
The store offers clothes accessories and footwear in addition it sells the home furnishing
goods and electronic items such as refrigerator air conditioner laptops and mobile
devices.
Using the Geolocation API the Geolocation API-enabled website can locate users current
geographical location display points of interest around that location or guide the users
from their current location to a target destination.
The users location is not retrieved just through code or browser. Instead the
Geolocation API uses certain features such as Global Positioning System (GPS) Internet
Protocol (IP) address of a device. Nearest mobile phone towers and input from user in
the users device to retrieve the users location.
getCurrentPosition()
watchPosition()
getCurrentPosition()
getCurrentPosition(callbackFunction,ErrorHandler,Options);
<html>
<body>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
</script>
</body>
</html>
watchPosition()
the watchPosition() method return the current location of a user and continuously update
the location while user is moving. The watchPosition ()
method takes the same parameter as the getCurrentPosition() method and returns
the same object.
<!DOCTYPE HTML>
<head>
<html>
<script type="text/javascript">
var watchID;
var geoLoc;
function showLocation(position)
function errorHandler(err) {
if(err.code == 1) {
function getLocationUpdate(){
if(navigator.geolocation){
geoLoc = navigator.geolocation;
else{
</script>
</head>
<body>
<form>
</form>
</body>
</html>
User may not provide the permission to access his location. This may raise an error in
your website. The error may also occur when a user checks the current location on a
mobile device and the device goes out of coverage area or the network connection is
time out error.
Permission_denied that the user has declined the request to share the
location
Timeout that the time given to retrieve the users location exceeded the
maximum limit.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
function showPosition(position) {
switch(error.code) {
case error.PERMISSION_DENIED:
break;
case error.POSITION_UNAVAILABLE:
break;
case error.TIMEOUT:
break;
case error.UNKNOWN_ERROR:
break;
</script>
</body>
</html>
Offline Support
Ensures that the website is available even when the user is not connected
to the network.
Reduces network load on the server. You can make your website work
offline by using the
The client-side storage refers to the process of storing data locally within the users
browser the date stored by using client-side storage is retrieved only when it is
requested the date stored in the key value pairs.
localStorage
sessionStorage
localStorage
the localStorage object allow you to store data without any expiration date. The implies
that the date stored by using the localStorage .
<!DOCTYPE html>
<html>
<body>
<div id="result"></div>
<script>
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML =
localStorage.getItem("lastname");
} else {
</script>
</body>
</html>
the sessionStorage object is used to store the data for only one session.
<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter() {
if (sessionStorage.clickcount) {
sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
} else {
sessionStorage.clickcount = 1;
} else {
</script>
</head>
<body>
<div id="result"></div>
<p>Close the browser tab (or window), and try again, and the counter is
reset.</p>
</body>
</html>
You must have faced a situation when the network connection is lost and you click the
back button in the browser to view the previous page.
Offline browsing that a website can be viewed even if the user is not
connected to the internet.
Speed that if the user request the web page which is already there in the
cache it is retrieved from the cache and not from the server.
Reduced server load that the web page if cached will always be made
available from the cache unless the browser detects that the cache manifest has
been updated on the server or user has cleared the browser cache.
Cache the files that need to be cached after they are downloaded for the
first time.
Fallback the task to be performed a user tries to fetch the uncached files.
<html manifest=”HotelFacilities.appcache”>
You can make use of jQuery in a web page to manipulate HTML element by using
jQuery. The using jquery before you need to download jquery-1.8.3.js file. It can be
referred to the web page by using the <SCRIPT>tag in the head section.
</SCRIPT>
The SCRIPT tag instructs the browser that the HTML document uses a script.
The src is used to path of jquery file store in your hard drive.
document.ready()
this function contains the jquery code to be executed on HTML element after the web
page has been fully loaded in the browser.
$(document).ready(function(){//jQuery code})
</SCRIPT>
The dollar sing ($) represent start of the jQuery code block and jQuery code is the code
to be implemented for the document.ready() function
$ (selector).action();
The selector is the element to be manipulated and action represents action to be taken
on the selector element.
<html>
<head>
</SCRIPT><SCRIPT>
$(document).ready(function(){//jQuery code})
</SCRIPT>
</head>
<body>
...
</body>
jQuery HTML
<head>
</SCRIPT><SCRIPT>
$(document).ready(function(){$("button").click (function() { $
("#para").prepend("<b>jQuery<b>"); $("#para").append('<h3> This is the
newly inserted heading.</h3>');
$("#newhead").remove();});});
</SCRIPT>
</head>
<body>
<div align="center"></div>
</body>
Hide
Show
Slide
Fade
Animate
Hide Effect
The hide() function is used to make an element disappear when an event such as click or
double-click occurs.
$(selector).hide(speed)
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></
script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").hide(1000);
});
});
</script>
</head>
<body>
<button>Hide</button>
</body>
</html>
The show() function is used to make a hidden element visible when an event occurs.
$(selector).show(speed)
<!DOCTYPE html>
<html>
<head>
<script src="F:\HTML\class\jQueryS
\jquery.1.8.3.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
</script>
</head>
<body>
<button id="hide">Hide</button>
<button id="show">Show</button>
</body>
</html>
Toggle Effect
The toggle () function is used to switch between the show and hide effects of an
element.
$(selector).toggle(speed)
<!DOCTYPE html>
<html>
<head>
<script src="F:\HTML\class\jQueryS\jquery.1.8.3.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();
});
});
</script>
</head>
<body>
</body>
</html>
Slide Effect
The slide effect used to produce a sliding effect on the selected element. The slide
functions slideDown() slideUp() and slideToggle()
slideDown()
$(selector).slideDown(speed)
slideUp()
$(selector).slideUp(speed)
slideToggle()
$(selector).slideToggle(speed)
<!DOCTYPE html>
<html>
<head>
<script src="F:\HTML\class\jQueryS\jquery.1.8.3.js"></script>
<script>
$(document).ready(function(){
$("#flip").mouseenter(function(){
$("#panel").slideToggle("slow");
});
});
</script>
#panel, #flip {
padding: 5px;
text-align: center;
background-color: #e5eecc;
#panel {
padding: 50px;
display: none;
</style>
</head>
<body>
</body>
</html>
Fade Effect
Fade effect is used to gradually reduce the opacity of the selected elements.
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></
script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeOut();
$("#div2").fadeOut("slow");
$("#div3").fadeOut(3000);
});
});
</script>
</head>
</div><br>
</div><br>
</div>
</body>
</html>
Animate Effect
Animate({params},speed,callback);
Callback the function that will be executed after completing the animation.
<!DOCTYPE html>
<html>
<head>
<script src="F:\HTML\class\jQueryS\jquery.1.8.3.js"></script>
<script>
$(document).ready(function(){
$("div").click(function(){
$("div").animate({
left: '250px',
opacity: '0.5',
width: '150px'
});
});
});
</script>
</head>
<body>
<div
style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>
</body>
</html>
Image Rollover
The images can be replaced by other images at runtime by creating the image rollover
effect.
<!DOCTYPE html>
<html>
<body>
<p>The function bigImg() is triggered when the user moves the mouse pointer
over the image.</p>
<script>
function bigImg(x) {
x.style.height = "64px";
x.style.width = "64px";
function normalImg(x) {
x.style.height = "32px";
x.style.width = "32px";
</script>
</body>
</html>
Image Gallery
An image gallery is a collection of thumbnail pictures or image links. All of these can be
clicked individually to provide a large view of the corresponding product on another web
page.
Colorbox plugin enables displaying a collection of images one by one by using the
previous and next button and variety of transition effects.
If you want to use this effect than you need to download a colorbox.zip file.
Colorbox this folder comprises the jquery.colorbox.js file. Is used to implement the
lightbox slideshow and the transition effects.
Colorbox.css style sheet contains the formatting instructions to stylize position and
decorate the image gallery.
<html>
<head>
<script src="F:\HTML\class\jQueryS\jquery.1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").colorbox({transition:"fade",height:"250",width:"220"});
});
</script>
</head>
<body>
<a href="a.jpg">shanu</a>
</body>
</html>
Galleria plugin
This plugin is used to display image gallery and create thumbnails of the images to be
displayed in the gallery automatically. When the mouse pointer is moved on a thumbnail
image is large version of image.
If you want to used galleria plugin you need to download the galleria.zip file