Htmltags
Htmltags
Page | 1
Welcome to any web page
</body>
</html>
Step2: Save the html document any name having. Html as the extension.
Step3: To execute the html document to open it in any Browser. To html language is
an error free language. That is it will not display any error massage on the Browser.
Even it the html document contain any error.
Html comments:
Comments are used to make the code name readable or they are
used to explain the code.
HTML comments begins with <!--line one comment-->
EX :<!--line one comment -- >
<!--line one comment
line two comment
.
.
.
N no. of line comments -- >
Attributes:
1. Attributes are used to provide additional information about the html elements
tags.
2. The attributes must be specified in starting tags.
3. The attributes always come in pears.
attribute name = attribute value
4. The attribute value can be enclosed with in single codes are double codes.
5. Every html tag can contain attribute.
Note: Specifying the attributes for a tag is optional.
Page | 2
3. Background: This attribute specify an image as the background to the html
document.
<body bgcolor = “#ffffoo” text = “#ffoooo”>
Good Afternoon
</body>
Note: Specifying the attributes is optional, we can specify any number of attributes
and they can specified in any order.
Formatting tags:
<b>: This tag is use to display a text in Bold face.
<b>Bold</b>
<strong>: This tag is similar to <b> used to display the text in Bold face.
<strong>Bold</strong>
<i>: This tag is use to emphasize a text by display in Italics format.
<i>Italics</i>
<em>: This tag is use to emphasize a text by display in Italics format.
<em>Italics</em>
<tt>: This tag is use to display a text in Teletype font. That is typewriter font.
<tt>Teletype</tt>
<s>: This tag is used to display a Strike the text.
<s>Strike</s>
<strike>: This tag is similar to <s> use to display a Strike out text.
<strike>Strike</strike>
<del>: This tag is use to Delete a text by Striking it out.
<del>Strike</del>
<ins>: This tag is use to Insert a line below the text.
<ins>underline</ins>
<u>: This tag is use to underline a text.
<u>underline</u>
<sup>: This tag is use to display a text as a Superscripted. That the text will be
a<sup>2</sup>+b<sup>2 displayed above the normal text.</sup>
<sub>: This tag is use to display a text as a Subscripted. That is the text will be
displayed below the normal text.
H<sub>2</sub>SO<sub>4</sub>
<big>: This tag is use display a text solidly Bigger then the normal text.
<big>text</big>
<small>: This tag is to display a text solidly Smaller then the normal text.
<small>text</small>
<center>: This tag is to display a text in the Center of the webpage(html document).
Page | 3
<center>Welcome</center>
Heading tags: These tags are used to perform font changes display the text in
boldface and the heading tags by default align the text tag left side. These are six
levels of heading tags. H1, H2, H3, H4, H5 and H6. H1 is the biggest in heading and H6
is the biggest in heading and H6 is the smallest heading.
We can change the alignment of the headings by using align attributes.
Ex: align = “left |center |right”
<H1 align = “left”>Heading1</H1>
<H2 align = “left”>Heading2</H2>
<H3 align = “center”>Heading3</H3>
<H4 align = “center”>Heading4</H4>
<H5 align = “right”>Heading5</H5>
<H6 align = “right”>Heading6</H6>
<pre>:(preformatted text)
This tag is used to display a text in preformatted manner. The browser
preserve all the white spaces as it is.
Ex:<pre>
To,
The manager,
HDFC bank,
Nellore,
Sub: Regarding loan to buy a house.
Respected sir/madam,
I………………………
…………………………
……………………….
Thanking you.
</pre>
<br>: This tag is used to stop displayed in the content at that point and displayed
content in a new line. The <br> will started new line where ever it is specified.
Note:<Br> is an empty tag that is <BR> tag doesn’t content any element content.
Ex:
<body>
line one</br>
line two</br>
line three
Page | 4
</body>
<p>: This tag is used to display a paragraph. The <p> will add paragraph break (inserts
an empty line before and after the paragraph). The paragraphs are is by default to
left side. We can change the alignment by using the alignment attribute.
<hr>: This tag is used to display a horizontal line in a html document. Using the
horizontal rule we can divide the web page into multiple sections.
*Attributes of <hr>:
1. Width: This attribute specifies the length of the Horizontal rule to be displayed
in a web page. The width can be specified either in pixels or percentage.
2. Color: This attribute specifies the color of the horizontal rule to be displayed in
a web page.
Ex:<hr color = “red”/>
3. Size: This attribute specifies the thickness of the horizontal rule to be displayed.
4. align: We can change the alignment of the horizontal rule by using this align
attribute. By default the horizontal rules are aligned to center.
Lists: In html document we can present the data in the form of list. There are 3 types
of lists.
Page | 5
1. Ordered List
2. Unordered List
3. Definition List
1) Ordered List: A list is said to be an ordered list if the items are displayed by
using either by digits or by Alphabets or Roman numbers. By default digits are
used to display order list. We can change the display by using “type” attribute.
Type = “1 | a | A | i |I|”
Ex: <ol type “I”>
<li>Hyderabad</li>
<li>Mumbai</li>
<li>Chennai</li>
</ol>
2) Unordered List: If a list is displayed with the help of some graphical symbols
then it is called as unordered list. We can change the display by using “Type”
attribute.
Type = “disc | square | circle”
Ex:
<Ul>
<li>Hyderabad</li>
<li>Mumbai</li>
<li>Chennai</li>
</Ul>
3) Definition List: A list is said to be a definition list if we provide a definition or
description to every item.
Ex:
<dl>
<dt>Hyderabad</dt>
<dd>Biriyani</dd>
<dt>Chennai</dt>
<dd>somber</dd>
<dt>Mumbai</dt>
<dd>bomb</dd>
</dl>
We can place a list inside another list that is nesting of lists is possible.
Ex:
<Ul>
<li>Hyderabad</li>
Page | 6
<ol>
<li>Ameerpet</li>
<li>Hi-tech</li>
<li>Birla temple</li>
</ol>
<li>Mumbai</li>
<li>Chennai</li>
</Ul>
<Font>: This tag can be used to apply font changes, change the text color or face or
size.
Attributes of <font>:
1. Color: This attribute specifies the color of the text to be displayed.
Ex: <font color = “red”> Hello </font>
Note: Font tag is dependent tag. That is <font> will not apply any changes without
the attributes.
<img> :(image) this tag is used to display and img on the html document.
Attributes of<img>:
1. Src(source): This attribute specifies of the URL(Address of the image).
2. Border: This attribute specifies of the thickness of the border around the
image. By default thickness is ‘zero’ pixels.
Page | 7
6. Hspace(Horizontal Space): This attribute specifies the amount of space empty
space to be displayed on the left and right sides of the image.
Ex:<img src = “smile.jpg” border = “2” width = “100” height = “100” alt = “smile
logo” hspace = “50” vspace = “30”/>
Note: An <img> is an empty tag and (source) “src” is a mandatory attribute to display
an image.
Page | 8
3. Valign: This attribute is used to align the text vertically. Valign = “top | middle
|bottom” by the default it is vertically aligned to middle. In this sub tags we
can also use align, bgcolor, and background attributes.
Ex: <html>
<head>
<title>Table<title>
</head>
<body>
<table border = “2” width = “150” height = “150” bordercolor =
“red” bgcolor = “pink” cellpadding = “10”>
<caption>number table</caption>
<tr>
<th>one</th>
<th>two</th>
<td align = “center”>three</td>
</tr>
<tr>
<td colspan = “2” align = “center”>four</td>
<td rowspan = “2” valign = “top” bgcolor = “red”>
six</td>
</tr>
<tr>
<td>seven</td>
<td>eight</td></tr>
</table>
</body>
<html>
<Marquee>: This tag use to display a scrolling text on a web page.
Attributes of <Marquee>:
1. Behavior: This attribute specifies the behavior of the scrolling text in a web
page.
Ex:
Behavior = “scroll | slide | alternate”(the default behavior is scroll)
2. Direction: This attribute specifies the direction in which the text will be
scrolled. By default the text scrolls towards left side.
3. Bgcolor: This attribute will display bgcolor to the scrolling text.
4. Scroll amount: This attribute specifies the speed of the scrolling text.
Ex:
<marquee behavior = “scroll” direction = “right” bgcolor = “red”
scrollamount = “45”>flash news</marquee>
Page | 9
<a>: This tag is use to create link b/w the html documents are any other web
resource.
Attributes of <a>:
1. Href(hyperlinking reference): This attribute specifies the URL(address) of the
resource to which the hyperlink as the link reference.
2. Target: This attribute will specifies were to open the linked document.
Target = “_self” | “_blank” (_under scor) the default value _self.
3. Name: This attribute is used to create named Anchor. The named anchor can
be used to jump from one location to another location with in a html
document.
Ex: <a href = “image.html” target = “_blank”>click here</a>
Frame: Frames can be used to display multiple html documents in the same browser
at the same time.
<frameset>: This tag is use to divide a frame into multiple frames.
Attributes of <frameset>:
1. Rows: This attribute is a list of values separated by a comma (,). The no. of
values in a list will decide the no .of horizontal divisions.
2. Cols: This attribute is a list of values separated by a comma (,). The no. of
values in a list will decide the no. of vertical divisions.
3. Border: This attribute specifies the thickness of the border with in a frameset.
<frame>: This tag represents and individual frame with in a frameset.
Attributes of <frame>:
1. Src(source): This attributes specifies the URL(address) of the html document to
be displayed with in the frameset.
2. Scrolling: This attribute will decide where there frame will contain a scrolling
bar of not.
Scrolling = “auto | yes | no”
The default scrolling value is also “auto”.
3. Name: This attribute is use to assign a name to a frame.
4. No resize: It is a flag which indicates that the frame can’t be resized.
Ex:
<html>
<frameset rows = “30%,*” border = “10”>
<frameset src = “welcome.html” noresize/>
<frameset cols = “100,*”>
<frame src = “sample.html”/>
<frame src = “image.html”/>
</frameset>
</frameset>
Page | 10
Note: The frameset tag must be written outside the <body>.
Forms: Form is an area which contains some input elements where the user can
provide the information. Forms are used to submit the data to the server are any
other resource. The html document can have any no. of forms. To create a form in
html document we use <form>.
Attributes of <form>:
1. Action: This attribute specifies the URL(address) of the server are any other
resource where the form data has to be submit.
2. Method: This attribute defines how to submit the form data to the server. The
most widely values are ‘get and post’. If the method value is ‘get’ then the
form data will be submitted to the server along with the URL. The form data
will be display in the address bar and hence doesn’t provide security to the
form data.
If the method value is ‘post’ then the form data will be submit to the server
separately form the URL. It will don’t display the from data in the address bar.
There by provides security to the form data.
Using ‘get’ we can send limited data only but using ‘post’ we can sent
unlimited data.
The default method value is ‘get’.
3. Name: This attribute is used to assign a name to a form for identification.
<Select>: This tag will provide the user a list of options form which the user can select
one option.
Page | 11
<Text area>: This tag allows the user to enter the data in multiple lines the size of the
text area can be specified by using rows and cols attribute.
Ex:
<html>
<head>
<title>Registration</title>
</head>
<body bgcolor = “green”>
<form method = “post” name = “registrationform”>username<input
type = “text” name = “user” size = “30”/><br/>
Password<input type = “password” name = “pass” size = “30”/><br/>
Confirm password<input type = “password” name = “cpass” size =
“30”/><br/>
Gender<input type = “radio” name = “sex”/>
Male<input type = “radio” name = “sex”/>
Female<input type = “radio” name = “sex”/><br/>
Qualification
<select>
<option>BTech</option>
<option>MCA</option>
<option>BSc</option>
<select><br/>
Hobbies
<input type =”check box”>programming
<input type =”check box”>browsing
<input type =”check box”>reading<br/>
Comments
<textarea rows = “5” cols = “30”>Enter your comments</textarea><br/>
<input type = “submit” value = “register”/>
<input type = “reset” value = “clear”/>
</form>
</body>
</html>
Special character in HTML:
This are those character which have special meaning with
the browser all these characters are not available in keyboard.
1. 4 & lt; (4 < 5)
2. 4 & gt; (4 > 5)
3. ®
Page | 12
4. ©
5. ™
6. Parsnd;
7. &
8. " Abterminal & quot; “Abterminal”
9. &a pos; solutions & apos; “solutions”
Xml: It’s transfer “Extensible Markup Language”. It is a markup language that provide
environment to create cross platform compactable file. Cross platform compatibility
means it is not specific to any operating system, any H/W, any S/W and etc.
. Xml is a standard given by ‘w3c’. To create tag based data.
. Xml is called as “Mother language” using which we can create other markup
languages. Like wml, vml, and mml etc.
. Xml is use to store and describe the data. Data means meaningful and
understandable information. Data can be stored in a text file or database or xml file.
Text file: The text file can content formatted and unformatted data.
. It doesn’t show any hierarchy among the data.
. It doesn’t show any relationships b/w the values.
. It doesn’t provide any tools to check or verify the correctness of the data.
. The text files are some time depended on the output.
Database: The database can content formatted data in the form of tables.
. In a database we require a separate of a query language to operate on the data.
. Database has to be used in language scale application.
. That data in a database is specific to the database s/w.
HTML XML
1. Html is use to display and format 1. Xml is use to store and describe
the data. the data.
2. Html contains predefined tags. 2. Xml contains user defined tags.
3. Html tags are not case sensitive. 3. Xml tags are case sensitive.
4. Html is error and free language. 4. Xml is not an error free language.
Page | 13
5. Html can be used to design web 5. Xml can be used to transfer data
pages. b/w in compatible.
6. Html document can content 6. Xml document can content only
proper and improper nesting. proper nesting.
7. Html can be used to apply styles 7. Xml can be use to structured the
on the data. data.
Uses of xml:
. Xml can be use to store the data permanently similar to a database.
. Xml can be use to create other “Markup language”.
. Xml can be use to create transfer data b/w incompatible types.
. Xml can be use to configure the resources in a web applications.
Ex: web.xml
. Xml document provides some instructions for installing the software.
XML DTD:
It stands for xml document type definition. It is used to create rules for writing the
xml document. It is provides legal building blocks using which we can define a
structure for the xml document.
Page | 15
1. Element: This is the most important building block. This building block is used
to create tags. Which can contain some text, or it can contain some other
element or it can be empty.
2. Attribute: This building block is used to create attributes which are used to
provide additional information about the element. The attributes must be the
specified in the staring tags and they come in name value pairs, the attribute
value must be enclosed in single codes (‘‘) or double codes (““).
3. Entity: this building block is used to create special characters that are to be
used in an xml document.
4. PcDATA (parsed character data): This data will be parsed by the parser and
they can expand the entities.
5. CDATA: its stands for ‘character data’. This data will not be parsed by the
parser and it can’t expand the entities.
Declaring an element:
1. Declaring an element which can be empty.
Syn :<! ELEMENT element-name EMPTY>
Ex :<! ELEMENT address EMPTY>
2. Declaring an element which contains PCDATA.
Syn: <! ELEMENT element-name (# PCDATA)>
Ex: <! ELEMENT roll no (#PCDATA)>
3. Declaring an element which can contain any data
Syn: <! ELEMENT element-name ANY>
EX: <! ELEMENT name ANY>
4. Declaring an element which contains sequence of child elements.
Syn: <! ELEMENT element-name (child-name1, child-name2….)>
Ex: <! ELEMENT student (roll no, name, mobile no, add)>
5. Declaring an element which must occur exactly one time.
Syn: <! ELEMENT element-name (child-name)>
Ex: <! ELEMENT student (roll no)>
6. Declaring an element which can occur zero or more times.
Sys: <! ELEMENT element-name (child-name*)>
Ex: <! ELEMENT student (mobile no*)>
7. Declaring an element which must occur at least one time (one or more times).
Sys: <! ELEMENT element-name (child-name+)>
Ex: <! ELEMENT student (mobile no+>
8. Declaring an element which must occur either 0 or 1 time.
Sys: <! ELEMENT element-name (child-name?)>
Ex: <! ELEMENT student (address?)>
Page | 16
Declaring attributes:
1. Declaring n attribute with a default value.
Sys :<! ATTLIST element-name attribute-name attribute-type “default”>
Ex :<! ATTLIST student course cDATA “xml”>
2. Declaring an attribute which is mandatory.
Sys :<! ATTLIST element-name attribute-name attribute-type #REAUIDED>
Ex :<! ATTLIST student course cDATA #REAUIDED>
3. Declaring an attribute which is optional.
Sys :<! ATTLIST element-name attribute-name attribute-type #IMPLIED>
Ex :<! ATTLIST student course cDATA #IMPLIED>
4. Declaring an attribute whose value is fixed.
Sys :<! ATTLIST element-name attribute-name attribute-type #FIXED “value”>
Ex :<! ATTLIST student fee cDATA #FIXED “3500”>
5. Declaring an attribute containing an enumerated list.
Sys :<! ATTLIST element-name attribute-name (en-value1, en-value2….)>
Ex :<! ATTLIST student branch (cse |it | eee |ese)>
Declaring an entity:
1. Declaring an internal entity.
Sys :<! ENTITY entity-name entity-value>
2. Declaring an external entity.
Sys :<! ENTITY entity-name SYSTEM URL>
Rules to be prepared for writing a xml document which stores student
information.
I. Create a tag by the name institute which should be the root tag.
II. Create as student as child tag to institute which must be available at least one
time.
III. Create roll no, name, mobile no, address as child tags to student tag.
IV. The roll no and name tags must be present exactly 1 time.
V. The mobile no tag can be available either 0 or 1 or more time.
VI. The address tag must be available either 0 or 1 time.
VII. Create hno, colony and city as child tags to address tag.
VIII. The hno, colony, city must be available exactly 1 time.
IX. Create course as an attribute to student tag as enumerated list of values.
X. Create type as an optional attribute under student tag.
XI. Create country as an attribute under address tag whose value is fixed.
Page | 17
XML PARSER:
To validate a xml document we required a xml parser. Xml parser is a
utility tool using which we can check where a xml document well format or not and
valid or not. Xml parser can even be used for processing the xml documents.
Ex:
SAX (Simple API XML Process)
DOM (Document Object Model)
Document Object model for Java (JDOM)
IDE:
It’s “transfer Integrated Development Environment”. It is used to speed of the
development of an application. Where reduces the development time.
Ex:
XML SPY
STYLUS STUDIO
Procedure to open XML SPY IDE: Click on start on select all program sales Alcove
Click on xml spy.
Procedure to create DTD rules: Click on file menu select new item select
DTD (Document Type Definition) click on OK.
Rules:
1. <!ELEMENT institute (student +)>
2. <! ELEMENT student (rollno, name, mobileno*, address?>
3. <!ELEMENT rollno (#pcDATA)>
4. <!ELEMENT name (#pcDATA)>
5. <!ELEMENT mobileno (#pcDATA)>
6. <!ELEMENT address (hno,colony,city)>
7. <!ELEMENT hno (#pcDATA)>
8. <!ELEMENT colony (#pcDATA)>
9. <!ELEMENT city (#pcDATA)>
10.<!ATTLIST student course (java|.net|oracle|html) “html” >
11.<!ATTLIST student type cDATA #IMPLIED>
12.<!ATTLIST student country cDATA #FIXED “india”>
Page | 18
1 <! DOCTYPE institute SYSTEM “D:\studrules.dtd”>
2 <institute>
3 Student course = “html” Type = “inspector”>
4 <rollno>123</rollno>
5 <name>Rams</name>
6 <mobileno>9949139899</mobileno>
7 <mobileno>8887776663</mobileno>
8 <address country = “india”>
9 <hno>2/202</hno>
10 <colony>nawabpet</colony>
11 <city>bond</city>
12 </address>
13 </student>
14 </institute>
Page | 19
</institute>
XML SCHEMA:
1. XML SCHEMA is used to define structure of the XML document.
2. XML SCHEMA is a XML based alternative to DTD.
3. XML SCHEMA is successor to XML DTD.
4. XML SCHEMA is written in XML.
5. XML SCHEMA provides more Richer and powerful functionality.
6. XML SCHEMA supports data types and data types.
7. We can create our own user defined data types based on predefined data
types.
8. XML SCHEMA supports name spaces.
Page | 20
Here, xxx represents the name of the complex element name x1 and x2 represent
name of the child elements any y1 and y2 represents the type of x1 and x2
respectively. Here, x1 and x2 order can’t be changed x1 must be followed by the x2
only.
Order Indicators:
1. Sequence: This indicator will indicate that specifying all the child elements is
mandatory and the order is fixed.
2. All: This indicator will indicate that specifies the child elements are mandatory
but order of the elements can be changed.
3. Choices: These indicators will indicate that we can use specifying that we can
use any one of the child element.
Occurrence indictors:
1. Minoccurs: This indicator will specify the minimum no. of times a tag or
element must occur.
2. Maxoccurs: This indicator will specify the maximum no. of times an element
can (optional) occurs.
Attributes:
Syn:
<xs: attribute name = “xxx “ Type = “yyy “/>
<xs: attribute name = “course“Type = “xs: string“default = “xml”/>
<xs: attribute name = “course“Type = “xs: string“default =”xml”/>
<xs: attribute name = “course” Type = “xs: string “fixed=”java”/>
<xs: attribute name = “course” Type = “xs: string“
use=”optional/required”/>
Restrictions: These restrictions allow the user to define acceptable values in a xml
document. The restrictions on xml elements are called as “facets”.
Page | 21
</xs:restriction>
</xs: SimpleType>
</xs: element>
The above pattern allow the user to enter the data of length three
characters, where every character lowercase alphabet.
Page | 22
The above pattern will allow the user to enter a data of length of data 4 character
where each character should be a digit.
<xs: pattern value = “([a-z])*”/>
The above syntax will allow the user to enter a data of any length but every character
should be a lower case alphabet.
<xs: pattern value = “([a-z][A-Z])+”/>
The above pattern will allow the user to enter a data containing one or more pairs of
lower case and the upper case alphabets respectively.
<xs: pattern value =”[0-9]{10}”/>
The above pattern will allow the user to enter a data of length exactly 10 character
where every should be a digit.
This restriction will allow the user to enter a data whose maximum length can be up
to ‘20’ characters.
<xs: length value = “10”/>
This restriction will allow the user to enter data whose length is exactly ‘10’
characters.
Page | 23
8. <xs: element name=“rollno” maxoccurs=“1” minoccurs=”1”>
9. <xs: simpleType>
10.<xs: restriction base = “xs: integer”>
11.<xs: pattern value = “[0-9][0-9][0-9]”>
12.</xs: restriction>
13.</xs: simpleType>
14.</xs: element>
15.<xs: element name = “name” maxoccurs = “1” minoccurs = “1”>
16.<xs: simpleType>
17.<xs: restriction base = “xs: string”/>
18.<xs: pattern value = “([a-zA-Z])*”/>
19.<xs: minLength value = “4”/>
20.<xs: maxlength value = “10”/>
21.</xs: restriction>
22.</xs: simpleType>
23.</xs: element>
24.<xs: element name = “mobileno” minoccurs = “2” maxoccurs = “5”>
25.<xs: simpleType>
26.<xs: restriction base = “xs:integer”>
27.<xs: pattern value = “[789][0-9]{9}”/>
28.</xs: restriction>
29.</xs: simpleType>
30.</xs: element>
31.<xs: element name = “address”>
32.<xs: complexType>
33.<xs: all>
34.<xs: element name = “hno” type = “xs: string”/>
35.<xs: element name = “colony” type = “xs: string”/>
36.<xs: element name = “city” type = “xs: string”/>
37.</xs: all>
38.<xs: attribute name = “country” fixed = “india”/>
39.</xs: complexType>
40.</xs: element>
41.</xs: sequence>
42.<xs: attribute name =”course” use = “required”>
43.<xs: simpleType>
44.<xs: restriction base = “xs: string”>
45.<xs: enumeration value = “html”/>
46.<xs: enumeration value = “xml”/>
47.<xs: enumeration value = “java”/>
Page | 24
48.<xs: enumeration value = “oracle”/>
49.</xs: restriction>
50.</xs: simpleType>
51.</xs: attribute>
52.<xs: attribute name = “type” use =”optional” type = “xs: string” default =
“regular”/>
53.</xs: complexType>
54.</xs: element>
55.</xs: sequence> Save as rules.xsd
56.</xs: complexType>
57.</xs: element>
58.</xs: schema>
Page | 25
Java script:
1. Java script is the most popular scripting language used one the internet. It’s
works all the browsers. Like internet Explorer, Firefox, Chrome etc.
2. Java script is designed to interact with the html document.
3. Java script code can be embedded into the html documents.
4. Java script is an interpreted language.
Note:
Java and java script are two different language designed for two different
purpose.
Page | 26
<script type = “text/java script”>
document.write(“welcome to my web site”);
</script>
</body>
</html>
Page | 27
<body onload = “didplay ()”>
</body>
</html>
2. Relational operators:
These operators are used for comparing the values. These
operators can also be called as comparison operators. The various relational
operators are less than, less than are equals, grater than, grater than are equal,
equals, not equals (<, <=, >, >=, ==, !=).
3. Logical operators:
These operators are used to combine the conditions or used
to compliment the result. The various logical operators are AND (&), OR (|),
and NOT (!).
4. Conditional operators:
Page | 28
This operator is also called as ternary operator and it is used
to perform some operators based on a condition. The conditional operator is?
and ; (question mark, semicolon).
Ex:
first = (x>y)? x:y;
if (x>y)
first = x;
else
first = y;
5. Assignment operators:
This operator is used to assign a value to a variable. The
various assignment operator are assignment (=), compound assignment
operators (+=, -=, *=, /=, %=).
Popup boxes:
1. Alert box:
This box is used to display a message on the browser which must be
compulsory read by user.
Syn:
alert (message);
The alert box will not allow the user provide for the until the user read the
message click on OK button.
2. Prompt box:
This box allows the user to enter some of the information.
Syn:
prompt (message);
Syn:
Prompt (message, default-value)
<html>
<head>
<script type = “text/JavaScript”>
var n = prompt(“enter a number”, “4567”);
Page | 29
document.write(“n=” + n);
</script>
</head>
<body>
</body>
</html>
3. Confirm box:
This box is used to take the confirmation from the user.
Syn:
confirm(message);
The confirm box contains two buttons OK and CANCEL. When the user
click on OK button it return is true. When the use click on CANCEL button it
returns false.
Ex:
<html>
<head>
<title>pop up boxes</title>
</head>
<body>
<Script type = “text/JavaScript”>
var status = confirm(“do you want to sleep”);
document.write(status);
</script>
</body>
</html>
Conditional statements:
These statements are used to execute a group of
statements based on a condition.
1. If statement:
This statement will execute a group of statements when a
condition is true.
Syn:
If (condition)
{
Statements to be executed
}
<html>
Page | 30
<head>
<title>conditional statement</title>
</head>
<body>
<script type = “text/JavaScript”>
if(1 < 2)
{
document.write(“Hello”);
}
</script>
</body>
</html>
2. if-else statement:
If the condition is true than if block is executed and when condition is false else
block is executed.
Syntax:
if (condition)
{
Statement1
}
else
{
Statement2
}
Ex:
<html>
<head>
<title>conditional statement</title>
</head>
<body>
<script type = “text/JavaScript”>
if(1 – 2)
{
document.write(“1 is smaller”);
}
else
{
Page | 31
document.write(“1 is bigger”);
}
</script>
</body>
</head>
3. switch statement:
This statement is used to execute an option from a group of
option from a group of options that are available.
Syn:
Switch (expression)
{
case value1 : statement1;
break;
case value2 : statement2;
break;
case value3 : statement3;
break;
case value4 : statement4;
break;
default : default statement;
}
Ex:
<html>
<head>
<title>conditional statement</title>
</head>
<body>
<script type = “text/JavaScript”>
var x = parseInt (prompt(“Enter a number”));
switch(x)
{
case1 : document.write(“one”);
break;
case2 : document.write(“two”);
break;
case3 : document.write(“three”);
break;
case4 : document.write(“four”);
Page | 32
break;
default: document.write(“wrong choice”);
}
</script>
</body>
</html>
Iterating statements: These statements are used to execute a group of statements
multiple times.
1. For loop:
This statement has to be used when we known the exact number of iterations.
Syn:
for(initialization; condition; increment/decrement)
{
Statements to be executed
}
Ex:
<html>
<head>
<title>Iterating statements</title>
</head>
<body>
<script type = “text/JavaScript”>
var fact = 1;
for(x=1; x<=10; x++)
{
fact = fact * x;
document.write(x+”!=” +fact+ “</br>”);
}
</script>
</body>
</html>
2. While loop:
This loop must be used when we do not know the exact no. of iterations.
Syn:
while(condition)
{
Statements to be executed
}
Page | 33
Ex:
<html>
<head>
<title>iterating statement</title>
</head>
<body>
<script type = “text/JavaScript”>
var n = parseInt(prompt(“Enter a table number”));
var x = parseInt(prompt(“Enter an other number”));
var i = 1;
while(i<=x)
{
document.write(n + “*” +i + “=” +(n*i) +”<br/>”);
i++;
}
</script>
</body>
</html>
3. Do…..while loop:
This loop has to be used when we do not know the exact number of iterations.
Syn:
do
{
Statements to be executed
} while (condition);
Difference b/w while and do….while loop?:
In a while loop if the condition is false for the 1st time then statements will be
execute “zero times”.
In a do….while loop if the condition is false for the 1st time statement will be
execute for “one time”.
Ex:
<html>
<head>
<title>iteration statements</title>
</head>
<body>
<script type = “text/JavaScript”>
Page | 34
n = praseInt(prompt(“Enter a table number”));
x = parseInt(prompt(“Enter an other number”));
var i = 1;
do
{
document.write(n + “*” +i+ “=” +(n*i) + “<br/>”);
i++;
}while(i<=x);
</script>
</body>
</html>
JavaScript objects:
JavaScript can be considered as an object oriented language, it
allows the user to use predefined objects or create user defined objects.
An object is a kind of data which contains properties and methods. Properties are
used to hold the values of an object and the methods represent the Actions that are
performed by the object.
1. String object:
If the user encloses any data in “double codes” than it is considered as string
object.
Ex:
<html>
<head>
<title>JavaScript objects</title>
</head>
<body>
<script type = “text/JavaScript”>
var type = “javascript”;
document.write(text +”<br/>”);
document.write(text.lenght +”<br/>”);
document.write(text.toUpperCase() +”<br/>”);
document.write(text.toLowerCase() +”<br/>”);
document.write(text.indexOf(“a”) +”<br/>”);
document.write(text.lastIndexOf(“a”) +”<br/>”);
document.write(text.replace(“java”,”VB”) +”<br/>”);
document.write(text.fontcolor(“red”) +”<br/>”);
</script>
</body>
Page | 35
</html>
2. Date object:
This object is used to perform operations on data and time.
Ex:
<html>
<head>
<title>date object</title>
</head>
<body>
<script type = “text/JavaScript”>
var date = new Date();
document.write(date + “<br/>”);
document.write(date.getDate() + “<br/>”);
document.write(date.getMonth() + “<br/>”);
document.write(date.getfullYear() + “<br/>”);
document.write(date.getHouse() + “<br/>”);
document.write(date.getMinutes() + “<br/>”);
document.write(date.getSeconds() + “<br/>”);
</script>
</body>
</html>
3. Boolean object: This object represents either true or false. Based on the value
we pass to the boolean object.
Ex:
<html>
<head>
<title>Boolean object</title>
</head>
</body>
<script type = “text/javascript”>
var b1 = new Boolean();
var b2 = new Boolean(0);
var b3 = new Boolean(1);
var b4 = new Boolean(true);
var b5 = new Boolean(false);
var b6 = new Boolean(“ “);
var b7 = new Boolean(“html”);
var b8 = new Boolean(null);
document.write(b1 + “<br/>”);
document.write(b2 + “<br/>”);
Page | 36
document.write(b3 + “<br/>”);
document.write(b4+ “<br/>”);
document.write(b5+ “<br/>”);
document.write(b6+ “<br/>”);
document.write(b7+ “<br/>”);
document.write(b8+ “<br/>”);
</script>
</body>
</html>
4. Array object:
This object is used to value store multiple values into a single variable.
Ex:
<html>
<head>
<title>Array Object</title>
</head>
<body>
<script type = “text/javascript”>
var names = new Array();
names[0] = “john”;
names[1] = “Khan”;
names[2] = “Zhan”;
names[3] = “Mallikarjuna”;
names[4]= “Suneel”;
document.write(names + “<br/>”);
for(i=0; i<names.length;i++);
{
Document.write(names[i] +”<br/>”);
}
document.write(names.reverse() +”<br/>”);
document.write(names.sort() +”<br/>”);
</script>
</body>
</html>
Page | 37
<title>Math Object</title>
</head>
<body>
<script type = “text/javascript”>
document.write(Math.min(4,6) + “<br/>”);
document.write(Math.max(4,6) + “<br/>”);
document.write(Math.floor(4.5) + “<br/>”);
document.write(Math.ceil(4.5) + “<br/>”);
document.write(Math.round(4.5) + “<br/>”);
document.write(Math.sqrt(a) + “<br/>”);
document.write(Math.random() + “<br/>”);
document.write(Math.PI + “<br/>”);
</script>
</body>
</html>
Javascript events:
Events are the actions that can be identified by javascript the
events will be generated automatically based on the user operations to perform any
operation when an event is generated. We generally take the help of functions.
1. onclick: This event will be generated when the user performs simple click.
2. ondblclick: This event will be generated when the user performs double click.
3. onkeydown: This event will be generated when the user clicks on a key and
not at released.
4. onkeyup: This event will be generated when the key is released.
5. onkeypress: This event will be generated when the key is pressed and
released.
6. onmouse down: This event will be generated when the user click on the
mouse left button and not at released.
7. onmouseup: This event will be generated when the mouse click is released.
8. onmousemove: This event will be generated when there is a change in the
move location.
9. onmouseover: This event will be generated when the mouse pointer is placed
on top of a text or image and etc.
10.onmouseout: This event will be generated when the mouse pointer is removed
from the top of a text or image and etc.
Page | 38
11.onload: This event will be generated when the html document is loaded on to
the browser.
12.onunload: The event will be generated when the html document is removed
from the browser.
13.onfocus: This event will be generated when the html element has the control.
14.onsubmit: This event will be generated when the user clicks on the submit
button.
15.onreset: This event will be generated when the user clicks on the reset button.
16.onchange: This event will be generated when there is a change in the value of
the HTML element an change.
17.onerror: This event will be generated when an error occurs in the document.
18.onresize: This event will be generated when there is a change in the size of the
frame.
//javascript
<html>
<head>
<title>Events</title>
<script type = “text/javascript”>
Function change()
{
var name = myform.user.value;
var col = myform.color.value;
document.bgcolor = col;
alert(name + “has changed the background
color to” + col);
}
</script>
</head>
<body>
<form name = “myform”>
UserName<input type = “text” size = “25” name = “user”/> <br/>
color<input type = “text” size = “25” name = “color”/><br/>
<input type = “button” value = “change” onclick = “change()”/>
</form>
</body>
</html>
Page | 39
<html>
<head>
<title>Events</title>
<script type = “text/javascript”>
function validate(loginform)
{
var name = loginform.user.value;
var pwd = loginform.pass.value;
var data = /\w/;
if(name.length==0)
{
alert(“ Enter your user name”);
loginform.user.focus();
return false;
}
else if((name.length<6) || (name.length>15))
{
alert(“user name length is not valid”);
loginform.user.focus();
return false;
}
else if(data.test(name))
{
alert(“user name character are not valid”);
loginform.user.focus();
return false;
}
if(pwd.length==0)
{
alert(“Enter your password”);
loginform.pass.focus();
return false;
}
}
</script>
</head>
<body bgcolor = “cyan”>
<center>
<h1>Loginform</h1>
<form name = “loginform” onsubmit = “return validate(this)”>
Page | 40
UserName<input type = “text” name = “user” size = “30”/><br/>
password<input type = “password” name = “pass” size = “30”/> <br/>
<input type = “submit” value = “Login”/>
</from>
</center>
</body>
</html>
We can write the javascript code internal to the html document or external to the
html document.
function validate(loginform)
{
…….
………… Save as
…………….. // validation.js
………………….
……………………….
}
To include the external javascript into a html document. We take help of “src”
attribute of <script>
<script type = “text/javascript” src = “validation.js>
</script>
CSS: its stands for “cascading style sheets”. CSS is used to define styles how to display
the html element. The styles how to display the html element.
Page | 41
1. Inline styles
2. Internal styles
3. External styles
1. Inline styles: If the styles are specified inside the tag then styles are called
as inline styles. These styles are applied to only that tag in which they are
specified.
Ex:
<h1 style = “color:blue; text-align:center;”> XYZ ltd </h1>
<h1 style = “color:red; font-family: arial;”> ABC LTD </h1>
<p style = “color:blue; font-style: italic; margin-left: 45t;”> this is a para
</p>
<p style = “font-size: 22pt;”> second para</p>
<hr style = “color:green;”/>
2. Internal styles: If the styles are specified with in the html document by
using <style> then those styles are called as internal styles. The internal
styles will be applied to all the tags available in that html document.
Ex:
<html>
<head>
<title>CSS</title>
<style type = “text/css”>
a:hover
{
color:red;
font-size:200%;
}
P
{
color:green;
font-family:arial;
}
h1
{
color:brown;
font-size:22pt;
}
body
Page | 42
{
backgroung-color:cyan;
}
</style>
</head>
<body>
</body>
</html>
3. External Style:
If the styles are specified out side the html document then
those styles are called as external styles. The styles available externally can
be applied to all the tags available in multiple html documents.
The external styles stored out side the html document. Must be saved with
any name (.) dot having.css as the extension.
Ex:
P
{
color:green;
font-family:arial; Styles.css
}
h1
{
color:brown;
font-size:22pt;
}
To use external style sheets within the html document we take help of <link>. The
<link> must be specified in the need section of the html document.
Syn:
<link type = “text/css” rel = “stylesheet” href = “styles.css”/>
In the html document we can write all the types of styles. But the preference
followed by the browser in displaying the html elements is
1. Inline styles
2. Internal styles
3. External styles
4. Browser Default styles
Page | 43
Page | 44
Page | 45