12.05.2015 Views

Web Technologies - Sreenivasa Institute Of Technology and ...

Web Technologies - Sreenivasa Institute Of Technology and ...

Web Technologies - Sreenivasa Institute Of Technology and ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Web</strong> <strong>Technologies</strong><br />

1. <strong>Web</strong> Programming, Building Internet<br />

Applications, Chris Bates 2 nd Edition, Wiley<br />

Dreamtech Pub. (I,II,III)<br />

2. Java Server Pages by Hans Bergsten, SPD<br />

O’Really pub. (V,VI,VII,VIII)<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


www<br />

• The World Wide <strong>Web</strong> (<strong>Web</strong>) is a system of interlinked<br />

hypertext documents accessed via the Internet.<br />

• With a <strong>Web</strong> browser, a user views <strong>Web</strong> pages that may<br />

contain text, images, videos, <strong>and</strong> other multimedia <strong>and</strong><br />

navigates between them using hyperlinks.<br />

• The World Wide <strong>Web</strong> was created in 1989 by Tim Berners-<br />

Lee, working at the European Organization for Nuclear<br />

Research (CERN) in Geneva, Switzerl<strong>and</strong> <strong>and</strong> released in 1992.<br />

• Tim Berners Lee is the father of WWW<br />

• Introduced first web browser (Netscape Navigator)<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


WWW<br />

• The World Wide <strong>Web</strong> Consortium (W3C)<br />

develops interoperable technologies<br />

(specifications, guidelines, software, <strong>and</strong><br />

tools) to lead the <strong>Web</strong> to its full potential.<br />

• W3C is a forum for information, commerce,<br />

communication, <strong>and</strong> collective underst<strong>and</strong>ing.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Introduction<br />

• Script : is a program which runs directly without precompilation<br />

Program:<br />

Program compile Output<br />

Script :<br />

HTML Browser Output<br />

• Browser: is a piece of software that enables you to<br />

view pages on the internet.<br />

Ex:- Netscape Navigator, Internet Explorer, Mozilla<br />

Firefox, Konquoorer.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• Protocol : HTTP, FTP<br />

• HTTP: The Hypertext Transfer Protocol (HTTP) is a generic,<br />

stateless, protocol. Is used for hypertext, name servers <strong>and</strong><br />

distributed object management systems.<br />

• A feature of HTTP is the typing <strong>and</strong> negotiation of data<br />

representation, allowing systems to be built independently of<br />

the data being transferred.<br />

• FTP : st<strong>and</strong>s for file transfer protocol. Used for sending files<br />

over the internet. Sending files to another location is called<br />

uploading.<br />

• URL: uniform resource locator is used to describe the address<br />

of the file, the browser is displaying or loading.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


HTML<br />

• Tim- Berners –Lee introduced HTML<br />

• Hyper Text Mark up Language<br />

• Markup:- Tags are used to mark the information<br />

• Provides non-linear access to the information (direct Access)<br />

• It is simple for developers <strong>and</strong> users<br />

• File has .html extension<br />

• HTML files are generally created in notepad <strong>and</strong> other text<br />

editors.<br />

• Tools generate .htm files<br />

• <strong>Web</strong> browser display the information present in the html<br />

document<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


HTML<br />

• It is used to format text <strong>and</strong> information.<br />

• The text is marked up with elements called as<br />

tags. Ex:- <br />

• Every html element begin with a start tag <strong>and</strong><br />

end with an end tag<br />

Ex:- hello world <br />

• Content of the web page: Title, body, image,<br />

hyper links, audio, video, pointers<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Structure of the HTML document<br />

<br />

<br />

Introduction to HTML <br />

<br />

<br />

Body of the document <br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


HTML Tag Types<br />

• HTML tags may tell a WWW browser to:<br />

– format the text (bold, italicize, etc.)<br />

– have an in-line image<br />

• make it into a header<br />

• have it be a link to another document<br />

• or any number of other things<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


How the Tags Work<br />

• The first part of the tag turns the tag<br />

on<br />

• The ending part of the tag, , contains<br />

the "/" slash character.<br />

• This "/" slash tells a WWW browser to stop tagging<br />

the text. Many HTML tags are paired this way.<br />

Think of the tag as a container.<br />

• If you forget the backslash, a WWW browser will<br />

continue the tag for the rest of the text in your<br />

document,producing undesirable results.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Steps to Creating a<br />

HTML Document<br />

• Open a text editor<br />

• Create your HTML document<br />

• Head - not displayed with body<br />

• Body<br />

• Save the HTML (extension of .htm or .html)<br />

• Display your HTML document in WWW browser<br />

window (Open File rather than Open Location)<br />

• Check your work <strong>and</strong> modify as necessary<br />

• Place it on the <strong>Web</strong><br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


HTML Examples<br />

• The Title of the Page<br />

• First level header<br />

• All of your file goes here<br />

• What you are not going to see on the page<br />

<br />

• What you are going to see<br />

• Unordered List<br />

– first item<br />

– second item<br />

• <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Common Tags Used<br />

• Opens <strong>and</strong> closes the<br />

HTML document.<br />

• This is the title of your page<br />

<strong>and</strong> will appear at the top of your browser’s<br />

window.<br />

• to Header sizes<br />

for titles <strong>and</strong> larger text formats. Or specify<br />

font size: <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Common Tags Used<br />

• <br />

– Sources an image file <strong>and</strong> needs no closing tag.<br />

• Place URL <br />

– Links text or images to the designated file.<br />

• text Bold text.<br />

• text Italic text.<br />

• text Underline text.<br />

• (no closing) Line break.<br />

• (no closing) Horizontal line.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


conclusion<br />

• <br />

• <br />

• <br />

• <br />

• --- <br />

• <br />

• <br />

• <br />

• <br />

• <br />

• ,, , ,, , <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• causes all the material between its<br />

<strong>and</strong> tags to be centered<br />

horizontally in the browser window.<br />

• Closing tag : when contents are to be<br />

presented closing tag is required. Otherwise<br />

no closing tag.<br />

Ex:- hello world <br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Intoduction to HTML Tags<br />

Header Tags<br />

…..<br />

Image tag :<br />

<br />

Body background color:<br />

<br />

Body background :<br />

<br />

Srolling text<br />

sitams college <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Nested list<br />

• <br />

CSE <br />

<br />

<br />

ECE <br />

<br />

<br />

<br />

I cse <br />

II cse <br />

iii cse <br />

I ECE <br />

II ECE <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• <br />

CSE <br />

<br />

I cse <br />

II cse <br />

iii cse <br />

<br />

ECE <br />

<br />

I ECE <br />

II ECE <br />

<br />

<br />

Type attribute :- a, A, i, I.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


DEFINITION LIST<br />

• A definition list is a list of terms <strong>and</strong> corresponding definitions.<br />

• Definition lists are typically formatted with the term on the left with the<br />

definition following on the right or on the next line.<br />

• The definition text is typically indented with respect to the term.<br />

• The opening list tag must be . It is followed by an optional list header<br />

(caption) <strong>and</strong> then by term names () <strong>and</strong> definitions<br />

().<br />

EXAMPLE :-<br />

<br />

List Header<br />

Term 1This is the definition of the first term<br />

Term 2This is the definition of the second term.<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


which could be rendered as:<br />

List Header<br />

Term 1<br />

This is the definition of the first term.<br />

Term 2<br />

This is the definition of the second term.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


table<br />

<br />

<br />

//represents heading content<br />

<br />

<br />

//represents row content<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Data in table is represented by using tag<br />

Ex:- reg no <br />

<br />

Attributes of <br />

Colspan, Rowspan<br />

Ex:- merge 2 cols <strong>and</strong> 3<br />

rows for the data element<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


<br />

<br />

<br />

Example program<br />

<br />

<br />

reg no name <br />

<br />

<br />

<br />

1<br />

a <br />

<br />

<br />

2<br />

b <br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


<br />

<br />

reg no name <br />

<br />

1<br />

a <br />

<br />

<br />

2<br />

b <br />

<br />

<br />

<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Some more attributes<br />

specifies the format of the group of columns<br />

Ex:-<br />

//specified before the tag<br />

<br />

<br />

<br />

The first specifies the alignment for the first column in the table<br />

The second specifies the alignment for the span of 4 colums in the table<br />

specifies the data alignment in the table<br />

specifies the vertical alignment (top, bottom, middle) of the data. It<br />

if effective when the rowspan of the col is more than 1.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


table example using colgroup <br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

regnamebranch%credits<br />

<br />

<br />

<br />

1acse8056<br />

<br />

<br />

<br />

<br />

Example Program<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


FRAMES<br />

• Frame allows the user to view multiple html<br />

documents at a time.<br />

Syntax:-<br />

<br />

<br />

<br />

<br />

Note:- appear after the of the html<br />

document<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Nested frame<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The target attribute of tag specifies the name of the frame<br />

where the contents is to displayed<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Meta tag<br />

• It is a html element that interacts with the search engine<br />

• Meta elements are not visible to the user of the site <strong>and</strong><br />

should be placed inside the header section of the html<br />

document.<br />

Syntax:-<br />

• <br />

-- Diplay the list of key aspects of the site. It gives precise<br />

information about the site to the search engine.<br />

• <br />

-- The description is a 4 to 5 line of text <strong>and</strong> is used by the search<br />

engine to catalog <strong>and</strong> display your site<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Html forms<br />

• It collects information from the people viewing the site.<br />

Ex:- username, password<br />

Syntax or <br />

Method indicates the way the web server organize <strong>and</strong> send you the output.<br />

“Post” causes changes to server data, ex:- updating a database<br />

“get” is used when the form does not cause any changes to the server database. Ex:- requesting<br />

database<br />

tag is used to create appropriate input elements on the form<br />

Ex:- textbox, textarea, buttons etc..<br />

• Syntax for <br />

<br />

Name indicates the name of the form element.<br />

Type indicates the type of the input element<br />

Value indicate the value that the input button sends to the server upon submission.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Creating form elements<br />

• Textbox<br />

<br />

• Submit button<br />

<br />

• Reset button<br />

<br />

• Textarea<br />

<br />

• Password element<br />

<br />

• Hidden element<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• Check box<br />

<br />

Example:-<br />

<br />

WT<br />

<br />

SPM<br />

<br />

MC<br />

<br />

ACA<br />

<br />

<br />

Name attribute categorise the checkboxes under the same group or different group.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• Radio Button<br />

<br />

Example:-<br />

<br />

WT<br />

<br />

SPM<br />

<br />

MC<br />

<br />

ACA<br />

<br />

<br />

Name attribute categorise the checkboxes under the same group or different group.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


utton<br />

<br />

1<br />

2<br />

3<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Cascading Style Sheets (CSS)<br />

• Css allow you to specify the style of the page<br />

elements separately from the structure of the<br />

document<br />

• The separation of structure from content<br />

allows greater manageability <strong>and</strong> makes<br />

changing the style of your document easier<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Creating styles<br />

• Using Style attribute (Inline styles)<br />

Ex:- <br />

• Using style element<br />

<br />

p { color:red; font-family: arial }<br />

• Using external style sheets ( external style)<br />

Ex:- Specifying style in .css file<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Inline style<br />

<br />

sitams <br />

sitams<br />

college <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Using style element<br />

<br />

P { font-size: 20pt; color: #0000ff }<br />

H1{ font-family: arial, sans-serif;<br />

font-size: 18pt;<br />

text-decoration: underline<br />

}<br />

<br />

Note: style tag appear in the head part of the html<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Using external link files<br />

• The syntax for including the external style sheet<br />

A { text-decoration : overline; }<br />

Li em { color : red;<br />

font-weight : bold;<br />

}<br />

Ul { margin-left : 2em ; }<br />

Note: The above specification is to be stored in a .css<br />

file like example.css<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Linking the .css file in a html file<br />

• the .css file is invoked in the html file by using<br />

the tag<br />

Synatx :<br />

<br />

Note : the tag appear in the of<br />

the html document<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


An example<br />

<br />

<br />

<br />

<br />

<br />

sitams <br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


more style attributes<br />

p, h1 { color: yellow;<br />

text-decoration: blink;<br />

font-weight: 10pt;<br />

font-size: 12px;<br />

}<br />

Here is the child element of .<br />

So this style is applicable all children of<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Font-size<br />

• Font-size is represented in two ways<br />

1. Relative-length measurement<br />

(vary based on the screen resolution)<br />

ex:- px, em, ex, %<br />

• em: the 'font-size' of the relevant font<br />

• ex: the 'x-height' of the relevant font<br />

• px: pixels, relative to the viewing device<br />

2. Absolute length measurement<br />

(do not vary based on the system)<br />

Ex:- in(inches), cm, mm, pt (1pt=1/72in),<br />

Pc(picas 1pc=12pt)<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• Font-weight :<br />

bold/normal/light/lighter/thick/thicker<br />

• Font-style : none/italic/oblique(similar to<br />

italic)<br />

• color : red/green/yellow<br />

• Font-family: arial, sans serif<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Body background<br />

• Background-image : url<br />

• Background-position : bottom<br />

right/center/top left/…<br />

• Background-repeat : no-repeat<br />

• Background-attachment : fixed<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Text<br />

• Text-indent : 1em<br />

• Text-align : center/left/right/justify<br />

Margin<br />

• Width : 20%<br />

• Height : 10%<br />

• Overflow : scroll<br />

• Margin-bottom/margin-left/margin-right/margin-top<br />

ex:- margin-left: 0.3 em<br />

• Padding (distance between the content inside an element <strong>and</strong> the edge of<br />

the element.<br />

Padding-top/padding-bottom/padding-left/padding-right<br />

Ex:- padding-left:0.5em<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


example<br />

Div<br />

{ background-color : red;<br />

margin-bottom : 0.5em<br />

font-size: 1.5em<br />

width : 50%<br />

overflow: scroll;<br />

padding-left : 0.5em<br />

}<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• The tag defines a division or a section in<br />

an HTML document.<br />

• The tag is often used to group blockelements<br />

to format them with style<br />

<br />

This is a header<br />

This is a paragraph.<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• The tag provides no visual change by itself.<br />

• The tag provides a way to add a hook to a<br />

part of a text or a part of a document.<br />

• When the text is hooked in a span element you can<br />

add styles to the content, or manipulate the content<br />

with for example JavaScript.<br />

sky is light<br />

blue in color.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• The tag defines preformatted text.<br />

• Text in a pre element is displayed in a fixed-width<br />

font (usually Courier), <strong>and</strong> it preserves both spaces<br />

<strong>and</strong> line breaks.<br />

<br />

Text in a pre element<br />

is displayed in a fixed-width<br />

font, <strong>and</strong> it preserves<br />

both spaces <strong>and</strong><br />

line breaks<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


JavaScript<br />

• Developed by netscape<br />

• Is a client side scripting language<br />

• No relation with java<br />

• Other scripting languages : JavaScript, Jscript,<br />

VBScript<br />

• Jscript is a product of Microsoft<br />

• Scripting languages are under ECMA<br />

( European Computer Manufacturers Association) script<br />

st<strong>and</strong>ard.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


JavaScript<br />

JAVA<br />

• Object-oriented lang.<br />

• Support inheritance,<br />

polymorphism<br />

• Support different data-types<br />

• Case-sensitive<br />

• General purpose prog. Lang.<br />

• Uses applets to interact with web<br />

applications<br />

• Product of sun-micro systems<br />

• Java has both<br />

Compiler/interpreter<br />

JavaScript<br />

• Object-based lang<br />

• Does not support inheritance <strong>and</strong><br />

polymorphism<br />

• Variables are treated as Strings<br />

only<br />

• Case-sensitive<br />

• client-side scripting lang.<br />

• Uses html to interact with web<br />

applications<br />

• Product of Netscape<br />

• Javascript is a interpreter<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


JavaScript introduction<br />

• The code is written in the tag of the <br />

document.<br />

• JavaScript treat the elements of the web-page as objects.<br />

• Objects in javascript<br />

document, window, string, math etc…<br />

• The methods of the class are invoked by the Objects.<br />

Ex:- document.writeln(“hello”);<br />

• HTML tags can be used within the “ “ to invoke the<br />

functionality of the tag<br />

Ex:-<br />

document.writeln(“hello”);<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• variables are declared by using “var”<br />

Ex:- var x,y,z; (treated as string data types)<br />

• User Input :- To take input from the user prompt() is<br />

used<br />

Synatx:- prompt(“Enter the value”,default value);<br />

Usage: - window.prompt(“enter x”,0);<br />

• User output :- To display output alert() is used<br />

Syntax :- alert(“javascipt program);<br />

Usage :- window.alert(“Hello”);<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Example program<br />

(The sum of two numbers)<br />

<br />

<br />

<br />

var a,b,c;<br />

a=window.prompt("enter a",0);<br />

b=window.prompt("enter b",0);<br />

c=parseInt(a)+parseInt(b);<br />

window.alert("The sum is: "+c);<br />

document.writeln("The Sum is: "+c+"");<br />

<br />

<br />

<br />

The sum of two numbers in javascript<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Control structures<br />

• for (var i=0;i


Control structures<br />

• if(condition)<br />

statement;<br />

• if(condition)<br />

statement1;<br />

else If(condition)<br />

statement2;<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Example for average<br />

<br />

<br />

<br />

var total,count,sum,avg,n;<br />

count=1; total=0;<br />

while(count


Switch-case<br />

Switch(choice)<br />

{<br />

case option1 : statement1;<br />

break;<br />

case option2 : statement2;<br />

break;<br />

case option3 : statement3;<br />

break;<br />

default : statement 4;<br />

break;<br />

}<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• Arithmetic operators<br />

+,-,*,/,%,++,--<br />

• Logical operators<br />

&&, || , !<br />

• Relational operators<br />

=,==,!=<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Squares of the numbers<br />

<br />

<br />

<br />

document.writeln("Square of numbers between 1 to 10");<br />

for(var i=0;i


Functions()<br />

Syantax:-<br />

function function-name(parameters list)<br />

{<br />

declarations;<br />

statement1;<br />

statement2;<br />

}<br />

Ex:- function fun(x,y,z)<br />

{ return x+y+z;<br />

}<br />

Note:- function either return value/ does not return value<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Square of a numbers<br />

<br />

<br />

<br />

var a;<br />

for(var i=1;i


Program for rolling dice using R<strong>and</strong>om<br />

number generation<br />

• Math.r<strong>and</strong>om() generates number between 0 <strong>and</strong> up to 1 but not including 1.<br />

Example:-<br />

<br />

<br />

<br />

for(var i=0;i


ecursion<br />

• Function which calls by itself either directly or indirectly.<br />

• Program to generate the factorial of series of numbers<br />

<br />

<br />

<br />

for(var i=0;i


Arrays<br />

• An array is a group of memory locations that all have the same name <strong>and</strong> are of same type.<br />

• Array commences from zero index.<br />

• The length of the array is obtained using length method<br />

Ex:- array_name.length<br />

• Declaration of one dimensional array<br />

var a=new Array(10); // 10 elements<br />

• Initialization of arrays<br />

var a=[10,20,30,40,50];<br />

(or)<br />

var a=new Array(10,20,30,40,50);<br />

var a=new Array[5];<br />

a=[10,20,30,40,50];<br />

• Accessing the elements of the array<br />

Using index from for-loop or for-in loop<br />

Ex:-<br />

for ( var i=0;i


Passing Arrays to Functions<br />

• The array is passed to a function by its name without<br />

brackets<br />

ex:-<br />

var a=new Array(10);<br />

sort(a); //where sort is a user defined function<br />

Exercise:-<br />

• Program to sort numbers using function<br />

• Program to search for an element in an array<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Multi-dimensional Arrays<br />

• Declaration of a two-dimensional array<br />

Ex:- var a;<br />

a=new Array(2); //allocate 2 rows<br />

a[0]=new Array(3); // 3 elements in 1st row<br />

a[1]=new Array(4); // 4 elemets in 2nd row<br />

• Initialization<br />

var a=[ [1,2,3], // 1 st row elements<br />

[4,5,6,7] ]; //2 nd row elements<br />

• Accessing the elements of an array<br />

for (var i in a)<br />

for( var j in a[i] ) document.writeln( a[i][j] );<br />

(or)<br />

for( var i=0; i


JavaScript : Objects<br />

Math Object<br />

• Math.r<strong>and</strong>om() generates number between 0 <strong>and</strong> up to 1 but not including 1.<br />

• Math.floor()<br />

• Math.ceil()<br />

• Math.square()<br />

• Math.max(x,y)<br />

• Math.min(x,y)<br />

• Math.abs(x)<br />

• Math.pow(x,y) // x y<br />

• Math.round(x)<br />

• Math.log(x);<br />

• Math.sin(x), Math.cos(x), Math.tan(x)<br />

• Math.sqrt(x)<br />

• Math.exp(x) // e x<br />

• Math.r<strong>and</strong>om()<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


String Object<br />

• The String object encapsulates the attributes<br />

<strong>and</strong> behavior of a string of characters.<br />

• The string object provides many methods for<br />

selecting characters from a string,<br />

combination of strings, obtaining substring of<br />

a string, searching for substring within a<br />

string, tokenizing strings, conversion to<br />

lowercase or uppercase etc…<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Methods<br />

• Let String s=“I am a javascript learner”;<br />

• charAt(index) – returns a string containing the character at the specified index. It<br />

returns null if there is no character at the specified index.<br />

• charCodeAt( index) – Returns Unicode value of the character at the specified<br />

index. If there is no character at the index, charCodeAt returns NaN (Not a<br />

Number).<br />

• Concat(string) – Concatenates its argument to end of the string that invokes the<br />

method.<br />

• fromCharCode(value1,value2 …) – converts a list of Unicode values into a string<br />

containing the corresponding characters.<br />

• index<strong>Of</strong>(substring) – method returns the position of the first occurrence of a<br />

specified substring starting from the begining<br />

• index<strong>Of</strong>(substring,index) – method returns the position of the first occurrence of a<br />

specified substring starting from position index towards the beginning<br />

• lastIndex<strong>Of</strong>(substring) – searches for the last occurrence of substring The method<br />

returns the starting index of substring in the source string or -1 if substring is not<br />

found.<br />

• lastIndex<strong>Of</strong>(substring, index) – searches for the last occurrence of substring<br />

starting from position index <strong>and</strong> searching toward the beginning of the string that<br />

invokes the method. The method returns the starting index of substring in the<br />

source string or -1 if substring is not found.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• Slice(start,end) – returns a string containing the portion of the string from<br />

index start through index end. If end index is not specified, it go up to end<br />

of the string.<br />

• Split(string) – splits the source string into an array of strings (tokens)<br />

where its string argument specifies the delimiter.<br />

• Substr(start,length) – returns a string containing length characters starting<br />

from index start in the source string. It goes up to the end, if the length is<br />

not specified.<br />

• toLowerCase() – returns a string in which all uppercase letters are<br />

converted to lowercase letters.<br />

• toUpperCase() – returns a string in which all lowercase letters are<br />

converted to uppercase letters.<br />

• toString() – returns same string as the source string.<br />

• value<strong>Of</strong>() – returns the same string as the source string.<br />

• isNaN() – returns true if the value is not a number<br />

Ex:- var s=f.t.innerText();<br />

if( s.isNaN()) { document.writeln(“Not a number”); }<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Wrapping strings into html tags<br />

• anchor( name) – wraps the source string into anchor element<br />

with name as the anchor name<br />

• blink() wraps the source string in a element.<br />

• Link (url) wraps the source stirng in an anchor element with<br />

url as the hyperlink location.<br />

• strike() wraps the source string in a element.<br />

• sub() wraps the source string in a element.<br />

//substript<br />

• sup() wraps the source string in a element.<br />

//superstript<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Boolean Object<br />

• Javascript provides wrappers for creating a boolean object.<br />

• Boolean object stores true/false value<br />

• To cerate a boolean number<br />

syntax :- var b=new boolean(booleanvalue);<br />

• booleanvalue specifies whether the value of the boolean<br />

object is true or false.<br />

• toString() – returns the string “true” if the value of the<br />

boolean object is true, otherwise returns the string “false”.<br />

• value<strong>Of</strong>() – returns the value true if the boolean object is true;<br />

otherwise returns false.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Number Object<br />

• Javascript automatically creates number objects to store numeric values in a<br />

javascript program.<br />

• var n=new Number(numeric value);<br />

• Methods :-<br />

toString(radix) – returns the string representation of the number. The radix is optional<br />

<strong>and</strong> represents the radix of the number. 2 represents binary, 8 represents octal <strong>and</strong><br />

10 represents decimal, 16 represents hexa<br />

value<strong>Of</strong>() – returns numeric value<br />

Number.MAX_VALUE – property represents the maximum value that can be stored in<br />

javascript.<br />

Number.MIN_VALUE – property represents the maximum value that can be stored in<br />

javascript.<br />

Number.NaN – this property represents not a number. If the value returned from the<br />

arithmetic does not result in a number.<br />

Ex:- if(parseInt(s))==Number.NaN) return true; else return false;<br />

(Or)<br />

if(s.value<strong>Of</strong>()==Number.NaN) return true; else return false;<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Example<br />

<br />

<br />

<br />

var s1="SITAMS";<br />

var s2="ColleGE";<br />

document.writeln(" String s1: "+s1+" String s2: "+s2+"");<br />

document.writeln("character at index 0 in "+s1+" is "+s1.charAt(0));<br />

document.writeln("character Code at index 0 in "+s1+" is "+s1.charCodeAt(0));<br />

document.writeln("Word from character code 65, 67,80, 56 is"+String.fromCharCode(65,67,80,56));<br />

document.writeln("Lower Case of string "+s2+" is: "+s2.toLowerCase());<br />

document.writeln("Upper Case of string "+s2+" is: "+s2.toUpperCase());<br />

document.writeln("2-4 slice of string "+s1+" is: "+s1.slice(2,4)); //s1.substring(2,4);<br />

document.writeln("Last index of S in"+s1+" is: "+s1.lastIndex<strong>Of</strong>("S",3)); // search from index 3 to the<br />

begining of the string<br />

document.writeln("2-4 substring of "+s1+" is: "+s1.substr(2,4)); // from index 2 displays 4 characters<br />

Document.writeln("subscript of "+s1+" is: "+s1.sub());<br />

document.writeln("superstript of "+s1+" is: "+s1.sup());<br />

document.writeln("strike through of "+s1+" is: "+s1.strike());<br />

<br />

<br />

<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


<br />

<br />

function validate()<br />

{<br />

var un=login.ln.value;<br />

var pwd=login.pwd.value;<br />

var c=un.charAt(0);<br />

if( un!=" " && pwd!=" ")<br />

{<br />

if( c >= 'a' && c='A' && c


if(pwd.length > 6)<br />

{<br />

//document.login.submit();<br />

//alert("succ");<br />

return true;<br />

}<br />

else<br />

{<br />

alert ("password must be atleast 6 chars");<br />

return false;<br />

}<br />

}<br />

else if (un!=" ")<br />

{<br />

alert (" username firt character must be a letter");<br />

return false;<br />

}<br />

}<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


contd…<br />

else<br />

{<br />

}<br />

alert ("enter all the fields");<br />

return false;<br />

}<br />

<br />

<br />

<br />


excercise<br />

Registration form validation<br />

• Validate phone number ( must be 10 digits)<br />

• Validate email id<br />

sitams@yahoo.com<br />

Check for the position of @ ( it should be >0)<br />

Check for the position of . (it should be > pos(@)+1)<br />

The length of email_id > pos(.)<br />

• Validate credit card number ( 16 digit number)<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


User Profile validation<br />

• Date of Birth<br />

• Validate age (numeric between 1-100)<br />

• Alternate email_id<br />

Credit Card Validation<br />

• Credit card Number validation<br />

• Pin number/ Username<br />

• Password<br />

• Address ( door number, street, city, state)<br />

• Amount ( some limit 10000-50000)<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Date object<br />

• Provides methods for date <strong>and</strong> time<br />

manipulations.<br />

• Date <strong>and</strong> time processing can be performed<br />

based on the computer’s local time zone or<br />

based on the worlds st<strong>and</strong>ard time called<br />

Coordinated Universal Time (UTC) or Greenich<br />

Mean Time (GMT).<br />

• The methods are available in local time zone<br />

version <strong>and</strong> in UTC version.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Methods in Date object<br />

• getDate() / getUTCDate() //returns a number from 1 to 31 representing the day of<br />

the month in local time or UTC<br />

• getDay() / getUTCDay() //returns a number from 0(Sunday) to 6(Saturday)<br />

representing day of the week in local time or UTC<br />

• getFullYear() / getUTCFullYear() //returns a 4 digit number as year in local time or<br />

UTC<br />

• getHours() / getUTCHours() //returns a number between 0 to 23 representing<br />

hours since since midnight in local time or UTC<br />

• getMilliseconds() / getUTCMilliseconds() //returns a number from 0 to 999<br />

representing number of millseconds in local time or UTC. The time is stored in<br />

hours, minutes, seconds <strong>and</strong> milliseconds<br />

• getSeconds() / getUTCSeconds() //returns a number from 0 to 59 representing<br />

number of seconds in local time or UTC.<br />

• getMinutes() / getUTCMinutes() //returns a number from 0 to 59 representing<br />

number of minutes in local time or UTC.<br />

• getMonth() / getUTCMonth() //returns a number from 0 to 11 representing<br />

month in local time or UTC.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• getTime () //returns the number of milliseconds between january 1, 1970 <strong>and</strong> the<br />

time in the Date object.<br />

• getTimezone<strong>Of</strong>fset() //returns the difference in minutes between the current time<br />

on the local computer <strong>and</strong> UTC.<br />

• setDate(val) / set UTCDate(val) // sets the date of the month (1 to 31) in local Time<br />

or UTC<br />

• setMonth(m,d) / setUTCMonth(m,d)<br />

• setFullYear(y,m,d) / setUTCFullYear(y,m,d)<br />

• setHours(h,m,s,ms) /setUTCHours(h,m,s,ms)<br />

• setMinutes(m,s,ms) /setUTCMinutes(m,s,ms)<br />

• setSeconds(s,ms) /setUTCSeconds(s,ms)<br />

• setMilliSeconds(ms) /setUTCMilliSeconds(ms)<br />

• setTime(ms) // sets elapsed milliseconds since january 1, 1970<br />

• toLocalString() // returns string equivalent of the the date <strong>and</strong> time specific to<br />

local computer time setting<br />

Ex:- 9/8/2009 15:30:35 for august 9, 2009 at 3:30:35 pm<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• toUTCString() // returns string equivalent of the date <strong>and</strong> time<br />

Ex:- august 9, 2009 at 3:30:35 pm for<br />

9/8/2009 15:30:35<br />

• toString() // returns the string representation of the date <strong>and</strong><br />

time in a form specific to the local computer.<br />

• value<strong>Of</strong>() – the time in number of milliseconds since midnight,<br />

january 1,1970.<br />

Usage:-<br />

var d=new Date();<br />

d.getTime();<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


example<br />

<br />

<br />

<br />

var current=new Date();<br />

document.writeln("toString: "+current.toString()+"");<br />

document.writeln("toLocalString: "+current.toLocalString()+"");<br />

document.writeln("toUTCString: "+current.toUTCString()+"");<br />

document.writeln("tovalue<strong>Of</strong>: "+current.value<strong>Of</strong>()+"");<br />

document.writeln("getDate: "+current.getDate()+"");<br />

document.writeln("getMonth: "+current.getMonth()+"");<br />

document.writeln("getFullYear: "+current.getFullYear()+"");<br />

document.writeln("getHours: "+current.getHours()+"");<br />

document.writeln("getMinutes: "+current.getMinutes()+"");<br />

document.writeln("getSeconds: "+current.getSeconds()+"");<br />

document.writeln("getMilliseconds: "+current.getMilliseconds()+"");<br />

document.writeln("getTimezone<strong>Of</strong>fset: "+current.getTimezone<strong>Of</strong>fset()+"");<br />

<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Dynamic HTML<br />

(DHTML)<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Event Model<br />

• onload – uses this event to call javascript function when document loading completes.<br />

Usage :- <br />

• onclick – uses this event to call javascript function when the element in the document is<br />

pressed.<br />

Usage :- <br />

<br />

• onmousemove – fires repeatedly whenever the user moves the mouse over the web page.<br />

Usage :- <br />

• onmouseover – occurs when the mouse cursor moves over an element<br />

• onmouseout – occurs when the mouse cursor moves out from an element<br />

• Onfocus – useful for form elements that allow user input. Onfocus fires when an element gains focus<br />

• Onblur – fires when an element loses focus<br />

Usage:- <br />

• onsubmit – occurs when the user submits a form<br />

• Onreset –occurs when the user resets a form<br />

Usage :- <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


onload event<br />

<br />

<br />

<br />

function load()<br />

{<br />

window.alert("the document is loaded");<br />

}<br />

<br />

<br />

<br />

the demo of onload event <br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


<br />

<br />

function validate()<br />

{<br />

alert("validation successful");<br />

}<br />

function bye()<br />

{<br />

alert("the form is cleared");<br />

}<br />

<br />

<br />

<br />

<br />

username : <br />

password :<br />

<br />

<br />

<br />

<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


<br />

<br />

function validate()<br />

{<br />

alert("validation successful");<br />

}<br />

<br />

<br />

<br />

<br />

username : <br />

password : <br />

<br />

<br />

<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Mouse coordinates<br />

• event.offsetX<br />

• event.offsetY<br />

• event.srcElement<br />

• event.srcElement.tagName<br />

• elementname.innerText<br />

Ex:- span tag content<br />

s.innerText=data;<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Mousemove event<br />

• <br />

• <br />

• <br />

• function mouse_move()<br />

• {<br />

• coordinates.innerText=event.srcElement.tagName+"("+event.offsetX+","+event.offsetY+")";<br />

• }<br />

• <br />

• <br />

• <br />

• (0,0)<br />

• <br />

• <br />

• <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


onmouseover & onmouseout<br />

<br />

<br />

<br />

function change()<br />

{<br />

event.srcElement.style.color="RED";<br />

}<br />

function nochange()<br />

{<br />

event.srcElement.style.color="black";<br />

}<br />

<br />

<br />

<br />

(0,0)<br />

<br />

SITAMS college <br />

<br />

CSE<br />

IT<br />

<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


DHTML: Filters & Transitions<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


Filters & Transitions<br />

• Many visual effects are implemented directly in the client-side<br />

browser<br />

• Filters <strong>and</strong> transitions do not add content to the web page,<br />

rather they present existing content in an engaging manner to<br />

capture the user’s attention.<br />

• Applying filters to text or an image causes changes that are<br />

persistent (permanent)<br />

• Transitions are temporary; applying a transition allows you to<br />

transfer from one page to another page with a pleasant visual<br />

effect ex:- r<strong>and</strong>om dissolve<br />

• Filters <strong>and</strong> transitions are applied to the web page elements<br />

using CSS filter property.<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


filters<br />

• Flip : flip filters are applied to the text<br />

• Types : flipv <strong>and</strong> fliph<br />

• Fliph – flips the text horizontally<br />

• Flipv – flips the text vertically<br />

• Usage :-<br />

SITAMS <br />

SITAMS <br />

SITAMS <br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


example<br />

<br />

<br />

<br />

s.filters(“revealTrans”).apply();<br />

s.filters(“revealTrans”).transition=1;<br />

s.filter.item(0). enabled=true;<br />

s.filters(“blur”).strength=10;<br />

<br />

<br />

<br />

sitams<br />

sitams<br />

<br />

<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR


• Filter types<br />

Mask filter<br />

Glow filter<br />

Blur filter<br />

Wave filter<br />

Invert filter<br />

Gray filter<br />

Xray filter<br />

chroma filter<br />

SREENIVASA INSTITUTE OF<br />

TECHNOLOGY & MANAGEMENT<br />

STUDIES, CHITTOOR

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!