Professional Documents
Culture Documents
<HTML> tag
The first tag in a document should be HTML tag. These are the tags thats tell a web browser where the HTML in
your document begins and ends.
<HEAD> tag
The head tag has the general information also called meta-information. Metadata means data about data.
Syntax------<HEAD>.</HEAD>
Description
<head>
<title>
<base>
Defines the base URL for all the links on the page
<link>
<TITLE> tag
Title is placed in head structure. Between the title tag type the title of the document. this will appear at the top
of the browsers site.
Syntax---<TITLE>..</TITLE
<BODY> tag
Body tag comes after head structure. In the body tag one can find all the stuff which should be displayed in Brower
window.. ie. text, graphics, links, images..etc. The most common attributes of body tag are
BGCOLOR,BACKGROUND,TEXT AND LINK
Syntax----<BODY>.</BODY>
EXAMPLE
Open a Notepad and type the following code.
<html>
<head><title>EXAMPLE</title></head>
<body bgcolor = green>Welcome to HTML!</body>
</html>
NOTE- when we save as HTML tag file ,you can use either .html extension or
.htm extension. with newer software it will be perfectly safe to use .html
.
Comments in HTML
extension
Comment tag is used to insert comments in HTML source code. Comments will be ignored by browser . you can
use comments to explain your code.
Syntax---
<!This is comment-->
Note that you need an exclamation point after the opening bracket, but not before the closing bracket.
EXAMPLE
<html>
<head><title>EXAMPLE</title></head>
<body >
<!This is body of the page-->
Welcome to HTML!</body>
</html>
Example
<html>
<head><title>EXAMPLE OF BOLD AND ITALIC
</title></head>
<body bgcolor = green>Welcome to HTML!
<B>THIS IS BOLD</B>
<I>THIS IS ITALIC</I>
<U>THIS IS UNDERLINE</U>
</body>
</html>
HEADINGS
<html>
<head><title>EXAMPLE OF BOLD AND ITALIC
</title></head>
<body bgcolor = green>Welcome to HTML!
<H1>THIS IS BOLD</H1>
<H2>THIS IS ITALIC</H2>
<H3>THIS IS UNDERLINE</H3>
</body>
</html>
NOTE-HTML automatically adds an extra blank line before and after a headings
EXAMPLE<html>
<head><title>EXAMPLE OF BOLD AND ITALIC
</title></head>
<body bgcolor = green>Welcome to HTML!
<H1 ALIGN=LEFT>THIS IS BOLD</H1></BR>
<H2 ALIGN=LEFT>THIS IS NOT BOLD</H2></BR>
<H3 ALIGN=LEFT>THIS IS FUULL BOLD</H3></BR>
</body>
</html>
ADDRESS
Address specifies information such as authorship and contact details for the current documents. Browser render
the content with paragraph-breaks before and after <ADDRESS> tag
Syntax------<ADDRESS>..</ADDRESS>
Example
<html>
<head><title>EXAMPLE address
</title></head>
<body bgcolor = red>Welcome to QPATH
<address>shahara state <br>
Lucknow </address>
<H1 ALIGN=LEFT>THIS IS BOLD</H1></BR>
<H2 ALIGN=LEFT>THIS IS NOT BOLD</H2></BR>
<H3 ALIGN=LEFT>THIS IS FUULL BOLD</H3></BR>
</body>
</html>
The following table list are available for text formatting in HTML
Table 2-Text Formatting tags
TAG
<b>
<big>
<i>
<small>
<strong>
<sub>
DESCRIPTION
Define bold text
Define big text
Define italic text
Define small text
Define strong text
Define supscripted text
<sup>
<del>
<u>
<strike>
<s>
Example
<html>
<head><title>EXAMPLE OF SMALL ,BIG , STRONG
</title></head>
<body>Welcome to HTML!
<STRONG>THIS IS BOLD</STRONG></BR>
<EM>THIS IS NOT BOLD</EM></BR>
<BIG>THIS IS FUULL BOLD</BIG></BR>
THIS IS FUULL SUP<SUP>HELLO</SUP>
THIS IS FUULL SUB<SUB>HELLO</SUB>
</body>
</html>
FONTS
Texts are displayed with a standard font(sanserif, vardana, new roman)
The FONT tag allows you to change font and can take up to attributes-FACE,COLOR ,SIZE.
Font
Size=number
Size=+number
Size=-number
Face=face-name
Color=color-name
Example
Size=2
Size=+1
Size=-1
Face=Times
Color=red
Purpose
Defines the font size
Increase the font size
Decrease size
Defines face name
Defines the font color
<html>
<head><title>EXAMPLE address
</title></head>
<body>Example of font and size and color
<p style=font-family: verdana>THIS IS BOLD</p></BR>
<h1 style=font-family: courier>THIS IS NOT BOLD</h2></BR>
<h2 style=font-size:80%>THIS IS FULL BOLD</h3></BR>
<h3 style=font-size:80%>THIS IS FULL BOLD</h3></BR>
</body>
</html>
CHARACTER ENTITIES
Some characters have some special meaning in HTML, like the less than sign(<) that defines the start of HTML tag.
If we want the browser to actually display these characters we insert character entities in the HTML source .
A character entity has three parts an amparsands (&), an entity name or a # and an entity number, and finally a
semicolon(;).To display a less than sign in HTML documents we must write &1t; or <.
The advantage of using a name instead of a number is that a name is easier to learn.
The disadvantage is that not all browsers supports the newest entity names. The support for entity number is very
good in almost all browsers. Entities are case sensitive.
NON-BREAKING SPACES
The most common character entity in HTML is the non-breaking spaces. Normally HTML will truncate space in the
text. If you write 10 spaces in your text HTML will remove 9 of them. To add all spaces to your text , use the
character entity.
Result
Description
Entity name
Entity number
Non-breaking space
 
<
Less than
<
<
>
&
Greater than
Ampersand
Quotation mark
Apostrophe
>
&
"
'
>
&
"
'
Example
<html>
<head><title>EXAMPLE address
</title></head>
<body>Example  <a href=abc:person@IP.com> of font and size and color
<h1 style=font-family: verdana>THIS IS BOLD</h1></BR>
<h2 style=font-family: courier>THIS IS NOT BOLD</h2></BR>
<h3 style=font-size:80%>THIS IS " FUULL BOLD</h3></BR>
</body>
</html>
<br> tag is used to end the line,but not to start the line.<br> tag breaks the line wherever you place it.<br> tag is
empty tag. It has no closing tag.
Example
<html>
<head><title>EXAMPLE OF SMALL ,BIG , STRONG
</title></head>
<body>Welcome to QPATH
<p> QPATH<br> is located<br> in Shahara state</p>
</body>
</html>
Horizontal Rules
The horizontal rule is useful effect. Horizontal rules are not allowed in headings.tag is <HR>
<html>
<head><title>EXAMPLE OF SMALL ,BIG , STRONG
</title></head>
<body>Welcome to QPATH
YOU ARE IN QPATH <hr>
YOU ARE NOT IN QPATH </body>
</html>
Paragraphs
Paragraphs are defines in <p> tag
<html>
<head><title>EXAMPLE OF SMALL ,BIG , STRONG
</title></head>
<body>Welcome to HTML!
<p>THIS IS FUULL PARA </p>
<p>THIS IS NEW PARA</p>
</body>
</html>
CENTER TAG
<html>
<head><title>Welcome To QPATH
</title></head>
<body>
<CENTER> YOU ARE IN QPATH </CENTER>
<LEFT> YOU ARE NOT IN QPATH
</LEFT>
</body>
</html>
DIV TAG
This tag is used to apply styles for a selected block of text.
Example<html>
<head><title>EXAMPLE OF SMALL ,BIG , STRONG
</title></head>
<body>< DIV align=left>Welcome to HTML!</DIV>
<DIV align=center>THIS IS FULL PARA </DIV>
<DIV align=right>THIS IS FULL PARA </DIV>
<RIGHT>THIS IS FULL PARA </RIGHT>
<p>THIS IS NEW PARA</p>
</body>
</html>
Example
<html>
<head><title>EXAMPLE OF IMAGE
</title></head>
<body>
<img src=C:images\img1.jpg width=48 height=68>
<p>THIS IS NEW PARA</p>
</body>
</html>
Alignment
<html>
<head><title>EXAMPLE OF IMAGE alignment
</title></head>
<body >
THIS IS NEW PARA
</body>
</html>
LINKS
Html use <A>(anchor) tag to create a link with another document. An anchor can point any resource on the web
page .
<html>
<head><title>EXAMPLE OF LINK
</title></head>
<body>
<font color=blue> Welcome to QPATH INFO SOLUTION</font>
<p><A href=https://www.qpath.infosolution.com>Click Here</A></p>
</body>
</html>
LISTING IN HTML
Lists are used to display information in a compact, tight format and are a useful asset to know about
Ordered information
Unordered information
Definitions
ORDERED LISTS
An ordered list is used to list items. An ordered list items with <OL> tag. Each list item starts with <LI> tag.
Example.
<html>
<head><title>EXAMPLE OF LISTING
</title></head>
<body>
<ol>
<li>Coffee</li>
<li>Tea</li>
</ol>
</body>
</html>
Numbering Style
numbers
Lower alpha
Upper alpha
Lower roman
Upper alpha
exm
1,2,3,4
a,b,c
A,B,C
I,ii,iiii,.
I,II,III,.
<html>
<head><title>EXAMPLE OF LISTING
</title></head>
<body>
<ol type=A>
<li>Coffee</li>
<li>Tea</li>
</ol>
<ol type=a>
<li>Coffee</li>
<li>Tea</li>
</ol>
<ol type=i>
<li>Coffee</li>
<li>Tea</li>
</ol>
<ol type=I>
<li>Coffee</li>
<li>Tea</li>
</ol>
<ol type=1>
<li>Coffee</li>
<li>Tea</li>
</ol>
</body>
</html>
UNORDERED LISTS
An unordered list is used to list items. An unordered list items with <UL> tag. Each list item starts with <LI> tag.
Example.
<html>
<head><title>EXAMPLE OF LISTING
</title></head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
</ul>
</body>
</html>
The following example demonstrate different type of unordered list available in HTML
<html>
<head><title>EXAMPLE OF LISTING
</title></head>
<body>
<ul type=disc>
<li>Coffee</li>
<li>Tea</li>
</ul>
<ul type=square>
<li>Coffee</li>
<li>Tea</li>
</ul>
<ul type=circle>
<li>Coffee</li>
<li>Tea</li></ul></body>
</html>
DEFINITION LISTS
A definition list is not a list of items. This is a list of terms and explanations of the terms. A Definition list starts
with <DL> tag. Each definition list start with <DT> tag and each definition list definition list start with <DD> tag.
Example-
<html>
<head><title>EXAMPLE OF DEFINITION
</title></head>
<body>
<dl>
<dt>Coffee</dt>
<dd>It is hot</dd>
<dt>Tea</dt>
<dd>It is so hot</dd>
</dl>
</body>
</html>
Tables are defined in <table> tag. A table is dived into rows and each row is divided in data cells(td tag). A data cell
can contain text letters, images , links ,etc
Tag
Description
Table
Defines a table
Th
Tr
Defines a row
Td
Defines a column
Caption
cellpading
Defines distance between the data in cell and the boundaries of the cell
cellspacing
Defines distance between the data in cell and the boundaries of the cell
Colspan
rowspan
Thead
Example
<html>
<head>
<title>Example of Table</title></head>
<body><table border=1><tr>
<th>Name</th>
<th>class</th>
</tr><th>Rollo</th>
</tr>
<tr><td>Ram</td>
<td>MCA</td>
<td>16</td></tr>
<tr><td>Ramesh</td>
<td>MCA2</td>
<td>166</td></tr>
</table>
</body>
</html>
<html>
<head>
<title>Example of Table</title></head>
<body><table border=1><tr>
<th>Name</th>
<th>class</th>
</tr><th>Rollo</th>
</tr>
<tr><td src=C:\images\img.jpg>Ram</td>
<td src=C:\images\img01.jpg>Ramesh</td>
<td>MCA</td>
<td>16</td></tr>
<tr>
<td src=C:\images\img1.jpg>Ramesh</td>
<td src=C:\images\img13.jpg>Ramesh</td>
<td>MCA2</td>
<td>166</td></tr>
</table>
</body>
</html>
Frameset tag
Example
<html><frameset rows=25%,50%,25%>
<frame src=frame1.html>
<frame src=frame2.html>
<frame src=frame3.html>
</frameset>
</html>
<frame src=frame3.html>
</frameset>
</html>
<INPUT>tagThe most used form tag is <input> tag. The type of input is specified with the type attribute .most commonly
used are given below..
TEXT FIELDS-
Text field are used when you want to enter letters, numbers, etc. Example
<html>
<head>
<title>Example of TextBox</title></head>
<body><form>FIRST NAME<input type=text name=firstname> <br>
LAST NAME<input type=text name=lastname>
</form>
</body></html>
RADIO BUTTON
<html>
<head>
<title>Example of Radio Button</title></head>
<body>
<form><input type="radio" name="male" value="sex">MALE <br>
<input type="radio" name="male" value="sex">FEMALE
</form>
</body>
</html>
CHECKBOXES
<html>
<head>
<title>Example of Check Boxes</title></head>
<body><form><input type=checkbox name=bike>I have a car <br>
<input type=checkbox name=car>I have a bike
</form>
</body>
</html>
LABELS
Some of the controls automatically have labels associated with them(like button) but most of have not (like
textbox, checkbox, radio button). For those controls that have implicit labels, user should use the value of the
attribute as the label string. The LABEL element is used to specify labels for controls that do not have implicit
labels.
Syntax---<LABEL></LABEL>
Example
<html>
<head><title>WORKING WITH LABEL CONTROL</title>
</head>
<body><table><tr><td><LABEL for=name>First Name</LABEL></td>
<td><input type=text name=first name id=fname></td>
</tr>
<tr><td><LABEL for=name>Last Name</LABEL></td>
<td><input type=text name=last name id=lname></td>
</tr>
</table>
<input type=radio name=sex value=male>MALE <br>
<input type=radio name=sex value=female>FEMALE
<input type=submit value=send>
<input type=reset value=reset>
</body>
</html>
DROPDOWN LIST
<html>
<head><title>WORKING WITH DROPDOWN LIST CONTROL</title>
</head>
<body><form><select name=car>
<option value=volvo>Volvo
<option value=safari>Safari
<option value= Toyota>Toyota
<option value=Boloro>Boloro
</form>
</body>
</html>
What is CSS?
Maybe you already heard about CSS without really knowing what it is. In this lesson you will
learn more about what CSS is and what it can do for you.
CSS is an acronym for Cascading Style Sheets.
HTML can be (mis-)used to add layout to websites. But CSS offers more options and is more
accurate and sophisticated. CSS is supported by all browsers today.
After only a few lessons of this tutorial you will be able to make your own style sheets using
CSS to give your website a new great look.
As you will note, the codes are more or less identical for HTML and CSS. The above example
also shows you the fundamental CSS model:
One way to apply CSS to HTML is by using the HTML attribute style. Building on the above
example with the red background color, it can be applied like this:
<html>
<head>
<title>Example</title>
</head>
<body style="background-color: #FF0000;">
<p>This is a red page</p>
</body>
</html>
Method 2: Internal (the tag style)
Another way is to include the CSS codes using the HTML tag <style>. For example like this:
<html>
<head>
<title>Example</title>
<style type="text/css">
body {background-color: #FF0000;}
h1{foreground-color:green;}
</style>
</head>
<body>
<h1>This is a red page</h1>
</body>
</html>
Method 3: External (link to a style sheet)
The recommended method is to link to a so-called external style sheet. Throughout this tutorial
we will use this method in all our examples.
An external style sheet is simply a text file with the extension .css. Like any other file, you can
place the style sheet on your web server or hard disk.
For example, let's say that your style sheet is named style.css and is located in a folder named
style. The situation can be illustrated like this:
The trick is to create a link from the HTML document (default.htm) to the style sheet (style.css).
Such link can be created with one line of HTML code:
Notice how the path to our style sheet is indicated using the attribute href.
The line of code must be inserted in the header section of the HTML code i.e. between the
<head> and </head> tags. Like this:
<html>
<head>
<title>My document</title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>
...
This link tells the browser that it should use the layout from the CSS file when displaying the
HTML file.
The really smart thing is that several HTML documents can be linked to the same style sheet. In
other words, one CSS file can be used to control the layout of many HTML documents.
EXAMPLES
Open Notepad (or whatever text editor you use) and create two files - an HTML file and a CSS
file - with the following contents:
default.htm
<html>
<head>
<title>My document</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>My first stylesheet</h1>
</body>
</html>
style.css
body {
background-color: red;
}
Now place the two files in the same folder. Remember to save the files with the right extensions
(respectively ".htm" and ".css")
color
background-color
background-image
background-repeat
background-attachment
background-position
background
Colors can be entered as hexadecimal values as in the example above (#ff0000), or you can use
the names of the colors ("red") or rgb-values (rgb(255,0,0)).
To insert the image of the butterfly as a background image for a web page, simply apply the
background-image property to <body> and specify the location of the image.
body {
background-color: #FFCC66;
background-image: url("butterfly.gif");
}
h1 {
color: #990000;
background-color: #FC9804;
}
NB: Notice how we specified the location of the image as url("butterfly.gif"). This means that
the image is located in the same folder as the style sheet. You can also refer to images in other
folders using url("../images/butterfly.gif") or even on the Internet indicating the full address of
the file: url("http://www.html.net/butterfly.gif").
Fonts
In this lesson you will learn about fonts and how they are applied using CSS. We will also look
at how to work around the issue that specific fonts chosen for a website can only be seen if the
font is installed on the PC used to access the website. The following CSS properties will be
described:
font-family
font-style
font-variant
font-weight
font-size
font
Text
Formatting and adding style to text is a key issue for any web designer. In this lesson you will be
introduced to the amazing opportunities CSS gives you to add layout to text. The following
properties will be described:
text-indent
text-align
text-decoration
letter-spacing
text-transform
p {
text-indent: 30px;
}
h1 {
text-decoration: underline;
}
h2 {
text-decoration: overline;
}
h3 {
text-decoration: line-through;
}
An example could be the word "headline" which can be presented to the user as "HEADLINE"
or "Headline". There are four possible values for text-transform:
capitalize
Capitalizes the first letter of each word. For example: "john doe" will be "John Doe".
uppercase
Converts all letters to uppercase. For example: "john doe" will be "JOHN DOE".
lowercase
Converts all letters to lowercase. For example: "JOHN DOE" will be "john doe".
none
No transformations - the text is presented as it appears in the HTML code.
As an example, we will use a list of names. The names are all marked with <li> (list-item). Let's
say that we want names to be capitalized and headlines to be presented in uppercase letters.
Try to take a look at the HTML code for this example and you will see that the text actually is in
lowercase.
h1 {
text-transform: uppercase;
}
li {
text-transform: capitalize;
}
Then we want the white wine links to be yellow, the red wine links to be red and the rest of the
existing links on the webpage to stay blue.
To achieve this, we divide the links into two categories. This is done by assigning a class to each
link using the attribute class.
Let us try to specify some classes in the example above:
<p>Grapes for white wine:</p>
<ul>
<li><a href="ri.htm" class="whitewine">Riesling</a></li>
<li><a href="ch.htm" class="whitewine">Chardonnay</a></li>
<li><a href="pb.htm" class="whitewine">Pinot Blanc</a></li>
</ul>
<p>Grapes for red wine:</p>
<ul>
<li><a href="cs.htm" class="redwine">Cabernet Sauvignon</a></li>
<li><a href="me.htm" class="redwine">Merlot</a></li>
<li><a href="pn.htm" class="redwine">Pinot Noir</a></li>
</ul>
We can hereafter define special properties for links belonging to whitewine and redwine,
respectively.
a {
color: blue;
}
a.whitewine {
color: #FFBB00;
}
a.redwine {
color: #800000;
}
As shown in the example you can define the properties for elements which belong to a certain
class by using .classname in the style sheet of the document.
1</h1>
1.1</h2>
1.2</h2>
2</h1>
2.1</h2>
2.1.2</h3>
The above could be headings of any document split into chapters or paragraphs. It would be
natural to assign an id to each chapter as follows:
<h1
...
<h2
...
<h2
...
<h1
...
<h2
...
<h3
id="c1">Chapter 1</h1>
id="c1-1">Chapter 1.1</h2>
id="c1-2">Chapter 1.2</h2>
id="c2">Chapter 2</h1>
id="c2-1">Chapter 2.1</h2>
id="c2-1-2">Chapter 2.1.2</h3>
...
Let us say that the headline for chapter 1.2 must be in red. This can be done accordingly with
CSS:
#c1-2 {
color: red;
}
As shown in the example above you can define the properties in a specific element by using #id
in the stylesheet of the document.
Borders
Borders can be used for many things, for example as a decorative element or to underline a
separation of two things. CSS gives you endless options when using borders in your pages.
border-width
border-color
border-style
border
The property border-color defines which color the border has. The values are the normal colorvalues for example "#123456", "rgb(123,123,123)" or "yellow" .
border-color: gold;
}
h2 {
border-width: 20px;
border-style: outset;
border-color: red;
}
p {
border-width: 1px;
border-style: dashed;
border-color: blue;
}
ul {
border-width: thin;
border-style: solid;
border-color: orange;
}
Show example
It is also possible to state special properties for top-, bottom-, right- or left borders. The
following example shows you how:
h1 {
border-top-width: thick;
border-top-style: solid;
border-top-color: red;
border-bottom-width: thick;
border-bottom-style: solid;
border-bottom-color: blue;
border-right-width: thick;
border-right-style: solid;
border-right-color: green;
border-left-width: thick;
border-left-style: solid;
border-left-color: orange;
}
What is a pseudo-class?
A pseudo-class allows you to take into account different conditions or events when defining a
property for an HTML tag.
Let's look at an example. As you know, links are specified in HTML with <a> tags. We can
therefore use a as a selector in CSS:
a {
color: blue;
}
A link can have different states. For example, it can be visited or not visited. You can use
pseudo-classes to assign different styles to visited and unvisited links.
a:link {
color: blue;
}
a:visited {
color: red;
}
Use a:link and a:visited for unvisited and visited links respectively. Links that are active
have the pseudo-class a:active and a:hover is when the cursor is on the link.
We will now go through each of the four pseudo-classes with examples and further explanation.
Pseudo-class: link
The pseudo-class :link is used for links leading to pages that the user has not visited.
In the code example below, unvisited links will be light blue.
a:link {
color: #6699CC;
}
Pseudo-class: visited
The pseudo-class :visited is used for links leading to pages that the user has visited. For
example, the code below would make all visited links dark purple:
a:visited {
color: #660099;
}
Pseudo-class: active
a:active {
background-color: #FFFF00;
}
Pseudo-class: hover
The pseudo-class :hover is used when the mouse pointer hovers over a link.
This can be used to create interesting effects. For example, if we want our links to be orange and
be italicized when the cursor is pointed at them, our CSS should look like this:
a:hover {
color: orange;
font-style: italic;
}
As you will remember from, the spacing between letters can be adjusted using the property
letter-spacing. This can be applied to links for a special effect:
a:hover {
letter-spacing: 10px;
font-weight:bold;
color:red;
}
Example 1b: UPPERCASE and lowercase
we looked at the property text-transform, which can switch between upper- and lowercase
letters. This can also be used to create an effect for links:
a:hover {
text-transform: uppercase;
font-weight:bold;
color:blue;
background-color:yellow;
}
The two examples gives you an idea about the almost endless possibilities for combining
different properties. You can create your own effects - give it a try!
Alternatively, you can set text-decoration along with other properties for all four pseudoclasses.
a:link {
color: blue;
text-decoration:none;
}
a:visited {
color: purple;
text-decoration:none;
}
a:active {
background-color: yellow;
text-decoration:none;
}
a:hover {
color:red;
text-decoration:none;
}
..Try on yourself..
JAVA SCRIPT
JavaScript is a client side, object-oriented and high-level scripting language.
Client side: Programs are passed to the computer when browser is on, and then computer runs them.
Java
<SCRIPT>JavaScript statement</SCRIPT>
A document can have multiple SCRIPT tags, and each can enclose any number of statements.
<html>
<body>
<script language=JavaScript>
document. write (QPATH INFOSOLUTION)
</script>
</body>
</html>
Explanation-- To insert a script in a HTML page, we use the <script> tag. Use the type attribute to define the
scripting language.
<script type=JavaScript>.
Then the JavaScript starts :The JavaScript command to write some output to a page is document.
Write.
Then the script tag has to be close.
Save the program as firstja.html in your drive.
Then open the file in any browser.
Note: Head section : Script that contain functions go to the head section of the document. Then we can
be sure that the script is loaded before the function is called.
Execute a section that is placed in the body section.
EXAMPLE:
<html>
<head>
<script language="javascript">
function message()
{
document. write("hello");
}
</script>
</head>
<body onLoad="message();"
</body>
Variables
A variable is a container for storing values. A variables value can change during the scripts execution.
CREATING A VARIABLE
To create a variable ,the var keyword is used with variable name ,a and is used once for declration. Variables can
be assigned values latter on or immediately followed by the name with an equal sign and the value they
represent.
By simple assigning a value
For example-x=45
With the keyword var it may e
var x=43
RULES FOR VARIABLE NAME
STRING
BOOLEAN
NULL
UNDEFINED
A value which is undefined is a value held by a variable after it has been created, and before a
value has been assigned to it.
JAVASCRIPT STATEMENTS
What is statements?
All JavaScript scripts are essentially a series of commands that are passed to the interpreter to be carried out
sequentially. JavaScript usually requires that each one be placed on a separate line. These lines of code are
referred to Statements.
CONTROL STATEMENTS
Control statements are designed to allow you to create scripts that can decide which lines of code are evaluated , or
how many times evaluated. Conditional statements are used to make decisions.
There are two types of control statements.
Conditional statements
Loop statements
Conditional statements
There are five types of conditional statements
i.
Syntax-
Example:
<html>
<body>
<script language=JavaScript>
var t=12;
if(t<2)
{
document. write(<b>WELCOME</b>)
}
else
{
document. write(NOT WELCOME);
}
</script>
</body>
</html>
ii.
:
ifelse statement
<html>
<body>
<script language=JavaScript>
var b=12;
if(t<2)
{
document. write(<b>Good Morning</b>)
}
else
{
document. write(<b>Good Evening</b>);
}
</script>
</body>
</html>
LOOP STATEMENTS
iii.
For loop:
: <html>
<body>
<script language=JavaScript>
for(count=1; count<=10; count++){
if(count==2)
Break;
document. write(<p>Loop: + count+</p>);}
}
</script>
</body>
</html>
While Loop:
<html>
<body>
<script language=JavaScript>
i=0;
while(i<5)
{
document. write (The value of i +i)
document. write(<br>);
i++;
}
</script>
</body>
</html>
Events
click
Change
Focus
Blur
Mouse over
Mouse out
Select
Occurs when
User clicks on form event or link
User changes value of text,textarea
User gives form element input area
User remove input focus from form elements
User moves mouse pointer on text or link
User removes mouse pointer from text or link
User select data
Event handler
onClick
onChange
onFacus
onBlur
onMouseOver
onMouseOut
onSelect
Submit
Load
Unload
onSubmit
onLoad
onUnload
ALERT BOX
Syntax---alert(msg)
Example
<html>
<head><title>Sample alert</title>
<script language=JavaScript>
Alert(welcome to ALERT);
</script>
</head>
CONFIRM BOX
It displays a confirm box with a specified message and OK and Cancel buttons.
Example-
<html>
<script>
var y=window. confirm(Are you sure to exit)
if(y)
window. alert(OK Final! , Exit Now);
else
window. alert(Sorry!..)
</script>
</html>
FUNCTIONS IN JAVASCRIPT
A function groups together a set of statements ,under a single name. We can break down the use of functions ,
then, into two logical categories.
Defining Function
Calling Function
Defining function
The function definition is a statement which describes the function like name, any value which is accepts , and the
statements which is function comprises of.
Example-
<script language=JavaScript>
function sam_box()
{
alert(I am called by a function);
}
</script>
Given down example describes function declaration and function caling
<html>
<head><title>JavaScript</title><script language=JavaScript>
function sam()
{
Alert(I am called by a function);
}
</script>
</head>
<body>
< A href=JavaScript onClick=sam()>Display alert box</a>
</body>
</html>
BUILT-IN FUNCTIONS
ISNAN()FUNCTION
----- isNaN(testValue)
floatValue=parseFloat(toFloat)
if(is NaN(floatvalue))
{
notFloat()
}
else
{
isFloat()
}
EVAL() FUNCTION
The eval() function executes a string as through it were JavaScript Statement.
Syntax---eval(string)
Where string is any string representing a JavaScript expression, statement, or sequence of statements.
Example--<html>
<body>
<script language=JavaScript>
var string1=2*3
document.write(eval(string1)=,eval(string1),<br>);</script>
</body>
</html>
<html>
<body>
<script language=JavaScript>
string1=123 hello java
string2=-1.678888
document.write(parseFloat(string1)=,parseFloat(string1))
document.write(<br>)
document.write(parseInt(string2)=,parseInt(string2))
</script>
</body>
</html>
ESCAPE() FUNCTION
The escape() function returns the ASCII encoding of an argument in the ISO latin character set , useful for
writing cookies to the cookies.txt.file.
Syntax-----escape(string)
Here the value returned by escape() is the same string with non-alphanumeric characters encoded in
the form of %xx , where xx is the ASCII encoding of a character in the string.
ARRAY OBJECT
JavaScript does not have an explicit array data type..However you can use built-in array object
and its methods to work with array in your application. Array object have methods to
reversing and sorting arrays. It has a property to determining array length.
To create an array object
Syntax- arrayObjectName=new array([array length])arrayObjectName=new
array(*element0,element1,+)
Examplevar myfriend=new array()
myfriend*0+=Qpath;
myfriend*1+=Info;
myfriend*2+=solution;
OR
var myfriend=new array(Qpqth,Info,Solution);
EXAMPLE--<html>
<body>
<script language=JavaScript>
a =new array(4);
for(i=0;i<4;i++)
{
a[i]=new array(4)
for(j=0;j<4;j++)
{
a*i+*j+=*+i+,+j++
}
}
for(i=0;i<4;i++)
{
Str=Row+i+.
for(j=0;j<4;j++)
{
str+=a[i][j]
}
document. write(str,<p>)
}
</body>
</html>
COOKIES IN JAVASCRIPT
Cookies are small amount of data stored by web browser. They allow you to store particular information about a
user and retrieve it every time they visit your page. Each user has their own set of cookies.
Cookies are typically used by web servers to perform functions such as tracking your visits to websites, enabling
you to log in sites , and storing your shopping card.
Cookies has following characteristics:
Setting a Cookie
The Document ,cookies property is used to set cookies in a JavaScript.
Syntax--document. cookie=name=value; expires=date; path=path; domain=domain; secure;
Exampledocument. cookie=username=qpath; expire=32/05/2013 00:00:00;
Retrieving Cookies
To retrieving all properties set by cookies for the current document , the document. Cookie property is used .
var x= document. cookies;
This returns a string comprising a list of name/value pairs , separated by semicolon, for all cookies that are valid
for the current document.
Example
username=qpath; password=abc23
Here two cookies are priviousaly set with username and second is with password..
EXAMPLE
The following program creates a webpage that prompts you for your name the first time you visit it , then store
your name in cookie and display your name in the pages on subsequent visit.
The first time you visit the page , it should ask for your name and store it in a cookie. If you visit the page again at
any point ,it will get your name from the cookie and display it within the page.
The cookie is given expiry date of 1 year from the current date, which means browser will remember your name
even if you close it and reopen it.
You can clear the cookies by clicking on Clear me link, which calls delete_cookie function and then refreshes the
page and prompt for your name again.
EXAMPLE---
<html>
<head><script language=JavaScript>
function set_cookie(name,value,expire_year,expire_month,expire_day,path,domain,secure)
{
var cookie_string=name+=+escape(value);
if(expire_year)
{
var expire=new Date(expire_year,expire_month,expire_day);
cookie string+=;expire=expire.toString();
if(path)
cookie_string+=;path=+escape(path);
if(domain)
cookie_string+=;domain=+escape(domain);
if(secure)
cookie_string+=;secure;
document.cookie=cookie_string;
}
function delete_cookie(cookie_name)
{
var cookie_date=new date();
Cookie_date.setTime(cookie_date.getTime()-1);
document.cookie=cookie_name+==;expires=+cookie_date.toGMTstring();
}
function get_cookie(cookie_name)
{
var result=document.cookie.match(cookie_name+=(.*?)(;$));
if(sesults)
return(unscape(results[1]));
else
return null;
}
if(!get_cookie(username))
{
var username=prompt(Please enter your name,);
if(username)
{
var current_date=newDate;
var cookie_year=current_date.getFullYear()+1;
var cookie month=current_date.getMonth();
var cookie(username,cookie_yaer,cookie_month,cookie_day);
document.location.reload();
}
}
else
{
var username=get_cookie(username);
document.write(Hi+username+,welcome to my website!);
document.write(<br><a href=\javascript:delete_cookie(username));
document.location.reload();\>forget about me</a>);
</script>
</head>
</html>
<html>
<head>
<script language=JavaScript>
function validate()
{
if(parseInt(document.forms[0].phone.value)!=document.forms[0].phone.value)
{
alert(enter the phone number, numbers only);
return false;
}
return true;
}
</script>
</head>
<body>
<h4>Simple javascript clientside validation of phone number</h4>
<form action=handler on submit=return validate();>
<p>phone:<input type=text name=txtbox id=phone/></p>
<p><input type=submit value=send/></p>
</form>
</body>
</html>
The following sample validates a phone number form field which will accept only numbers and special characters
namely (,),+, and -.All other special characters are ignored. Here the name and email are also verified for null
values using JavaScript.
<head>
<title>JavaScript Validation</title>
<script language=JavaScript>
function VerifyData()
{
var valid=1
if(document.Customer.FirstLast.value==)
{
valid=0
}
if(document.Custmer.Email.value==)
{
valid=0
}
if(!CheckPhoneNumber(document.Customer.Phone.value))
{
valid=0
}
if(!valid)
{
alert(Please complete all the form and valid phone number)
}
return valid
}
function CheckPhoneNumber(TheNumber)
{
var valid=1
var GoodChars=02345678()-+
var i=0
if(TheNumber== )
{
valid=0
}
for(i=0;i<=TheNumber.length-1;i++)
{
if(GoodChars.indexOf(TheNumber.charAt(i))=-1)
{
valid=0
}
return valid
}
</script>
</head>
<body>
<h2>Client side validation in HTML form elements</h2>
Press the verify button to verify data.
<p>
<form name=Customer action= method=POST onsubmit=return VerifyData>
Your name:
<input type=text name=nme size=30 maxlength=75 value=><br>
Email:
<input type=text name=Email size=30 maxlength=75 value=><br>
Phone Number:
<input type=text name=phone size=30 maxlength=75 value=><br>
<input type=submit>
<input type=reset>
</form>
<p>
</body>
</html>