HTML5 and Web Design Fundamentals
HTML5 and Web Design Fundamentals
Download Bootstrap
Bootstrap Images
Bootstrap Dropdowns
Etc.,
Angular
47.What is Angular JS and Angular 2
48.What is SPA
49.Getting started with Angular
50.Angular Components
51.Property & Event Binding
52.Class & Style Binding
53.Two way data binding
54.Template Reference Variables
55.Angular Directives
56.Component Interaction
57.Angular Pipes & Filtering
58.Angular Services
59.Angular Form Validations
60.Dependency Injection
61.Routing and Navigation
62.Custom Directives
Projects
1. Classroom Projects
One UI Development Project
Web Designing-HTML
Introduction of HTML:
In 1980, mark up language was developed to create web document or web site, it is called HTML.
Web: Massive (large) collection web documents / web pages.
Web documents carrying hypertext data.
Internet: Internet is a massive (large) network of networks. It connects millions of
computers together globally.
Information that travels over the internet variety of languages known as protocols.
www (world wide web): It is a way of accessing information over the medium of internet.
The web uses browsers (Mozilla Firefox, Internet explorer, Google chrome … etc). Web
documents also contain graphics, sound, text and video.
HTML: [Hyper Text Markup Language]
HTML was interpreted by web client using web browser. It has some vocabulary rules.
Web Server
Internet
Web Client
request
Web server checks the request resource and it sends the information to the web client in
the same language protocol.
Advantages of HTML:
6. It is widely used.
7. Search engines. (Ex: google, yahoo, …… etc)
8. Social Networks. (Ex: facebook, twitter, .... etc)
9. E-Comm. (Ex: tansactions for on-line shopping’s)
10. TV ( TV over internet )
Disadvantages of HTML:
11. It can create only static and plain pages so if we need dynamic pages then HTML is not
useful.
12. Need to write lot of code for making simple webpage.
13. Security features are not good in HTML.
14. If we need to write long code for making a webpage then it produces some complexity.
- - - - - - - - - - - -
Common Tags:
Tags:
17. Tags are represented by angled brackets. ( < > )
18. They are not case sensitive, i.e <head>, <HEAD> (both are equal)
19. If a browser not understands a tag it will usually ignore it.
20. White space, tabs and new lines are ignored by the browser.
Ex: Body tag, paragraph tag, heading tag, hr tag, font tag, bold tag, italic tag,..etc
- - - - - - - - - - - -
hr tag: Horizontal lines can be added to the HTML document using <hr> tag. This tag does not
have any closing tag.
Syntax/Represented as: <hr>
Width, colour, size attributes are used in this tag.
<hr width = “value”> The value can be specified in percentage i.e 25%, 50%, 75% and so on.
<hr size=”value”> The thickness of the line in this expressed in terms of pixels.
<hr size =”5” width=”50%” >
Bold tag: This tag is used for implement bold effect on the text.
Syntax/Represented as: <b> HTML </b>
Break tag <br>: This tag is used to break the line and start from the next line.
Syntax/Represented as: <br>
Body tag: The body of an HTML document contains the text will show up on the web page.
Attributes are: <body bgcolor=”value”> ………… </body>
<body text=”value”> ………… </body>
<body bgcolor=”#0000FF” text=”FF0000”> ………… </body>
Font Tag: This sets font size, color and relative values for a particular text.
Syntax/Represented as: <font face=”value” size=”value” color=”value”>
Ex: <font face=”Arial” size=”10” color=”#FF0000”>
Attributes are:
Face: This attribute is used to set the font style.
21. <font face=”value”> Text </font>
Few of the values for the face attribute are given below:
63. Arial
64. Times new Roman font
65. Arial Black
66. Impact
Size: This attribute is used to specify the size of the text.
<font size=”value”> Text </font>
The possible values are : 1,2,3 and so on. <font size=”1”>
The text will displayed in 8pt size, if the size is 2 then text as 10pt, 3 is 12pt and
so on.
Color: This attribute is used to specify the color of the text.
<font color=”value”> Text </font>
Color Hexadecimal
value
Red #FF0000
Green #00FF00
Blue #0000FF
White #FFFFFF
Black #000000
Gray #808080
Dark #800000
Red
Dark #008000
Green
Dark #000080
Blue
Yellow #FFFF00
Magenta #FF00FF
Cyan #00FFFF
Strike effect: It is used to display the text in the browser, which has been striked and is
normally used to highlight the text.
Syntax/Represented as: <strike> Gopi Krishna </strike>
Marquee tag: It is used to display content or image in moving or scrolling. By default it will
move around the web page from right to left.
Syntax/Represented as: <marquee> gopi </marquee>
<marquee direction=right>SAI</marquee>
</body>
</html>
Create web page document for font tag, break tag and paragraph tag.
<html>
<head>
<title> Font Styles </title>
</head>
<body>
<p> <font face=”Arial” size=4 color=”blue”>
<B><I>
To specify the beginning of the paragraph and the end of
paragraph, </p>
<p> tag is used. </p>
</font> <br>
<p align=”center”>
<font face=”Arial” size=4 color=”Green”>
Siddartha Degree & PG College <Br>
Nalgonda. 508001 </p>
</font>
</body>
</html>
- - - - - - - - - - -
Lists: A list is collection of items. A list may contain any number of sub lists.
We can arrange items in lists in several ways. HTML, supports three types
22. Ordered list (Numbered list)
23. Unordered list (Bulleted list)
24. Definition list
Ordered List (Element OL): The element OL defines an ordered list. The element contains one
or more list elements.
<OL start=”number” type=”value”> Text to be displayed
</OL>
Attributes are: Start: Starting alpha/number/roman (a/A/i/I/1)
Type: Type of ordered list (a/A/i/I/1)
Here the ‘value’ attribute can be
A – Uppercase Alphabetic
a – Lowercase Alphabetic
I – Uppercase roman
i – Lowercase roman
1 – Decimal number (used by default)
Unordered List (Element UL): The element UL defines an unordered list. The element contains
one or more list elements.
<UL type=value> Text to be displayed
</UL>
Here the “value” can follow these symbols like disc, circle and square.
Attributes are: Type: circle, square and disc
- - - - - - - - - - - -
Hyper Link: To navigate (link) from one page to other (or) same page/image.
Hyper links are two types.
i) External ii) Internal
<a> anchor tag is used to hyper link.
Syntax: <a href=”URL” > text-to-click </a>
<a name=value> - - - - </a>
Attributes are: href: Hypertext Reference that contains the URL (Uniform Resource Locator)
Which is the address or location of the link.
name: This attribute of the anchor tag is used to identify a location within the
same HTML document.
i) External link: <a href=”file”> Text </a>
ii) Internal link: <a href=”#file”> Text </a>
The most common image types on the web are .GIF, .JPG and .PNG
<head>
<title> Anchor tag </title>
</head>
<body>
<a href="2.gif"> IMAGE </a>
</body>
</html>
- - - - - - - - - - - -
How it works:
The controls attribute adds audio controls, like play, pause and volume. The source (src)
element allows you to specify alternative audio files. The text between the <audio> and </audio>
tags will only be displayed in browser that do not support the <audio> element.
Ex: <audio controls>
<source src=”horse.ogg” type=”audio/ogg”>
<source src=”horse.mp3” type=”audio/mpeg”>
Your browser does not support the audio element.
</audio>
- - - - - - - - - - - -
Tables: Introducing Tables, Grouping Section of a Table, Nested Tables, Accessing Tables
HTML table consists of rows, columns and cell.
i. Tables are defined with the <table> tag.
<table> - - - - - </table>: This tag marks the beginning and end of the table.
Syntax: <table align=”value” border=”value” cell padding=”value” cell spacing=”value”
Width=”value”>
----
----
</table>
Table tag attributes:
align: Specifies the alignment of the table in the page. Values are left/right/center.
border: Specifies the width of the border to be drawn around all table cells. By default,
there is no border drawn. Values possible are 1,2,3 and so on.
cell padding: The space between the content and inside edge of a cell. Values are 1,2,3 and so on.
cell spacing: The amount of space between cells in a table. Values are 1,2,3 and so on.
width: It specify the width of the table. The maximum size of the monitor in pixels.
ii. The <table> tag contains rows of cells, defined with the <tr> tag.
<tr> - - - - </tr>: This tag are used to beginning and end of the row.
Syntax: <tr bgcolor=”value”>
----
</tr>
tr tag attribute:
bgcolor: This attribute is used to set the background colour of the row.
iii. Each <tr> tag contains data cell, defined with the <td> tag
<td> - - - - - </td> This tag are used to beginning and end of the data.
syntax: <td align=”value” colspan=”value” rowspan=”value”>
----
</td>
td tag attribute:
align: The align attribute checks the horizontal alignment of the text within the cell.
Values could left/right/center.
clospan: The colspan attribute checks the width of the cell in terms of number of
columns. Used when a cell occupies more than one column.
rowspan:The rowspan attribute checks the height of the cell in terms of number of
rows. Used when a cell occupies more than one row.
iv. Each data cell contains whatever you want links, images, lists or even other tables.
Create a web page using table tag. (Sample table for 2x2 matrix)
<html> Output:
Create a web page using table tag with attributes. (Sample table for 2x2 matrix)
<html> Output:
<caption> - - - - - </caption>
This tag is used to title/caption for a table, it describes the contents of the table.
caption tag attribute: align: Specifies the location of the caption.
Valid options are top/bottom
<th> - - - </th>
This tag is used to give column heading which names the information stored in it.
Create a super market web page using table, tr, th & td tag.
<html>
<head> <title> Supermarket </title> </head>
<body>
<h1 align=center> Super Market </h1>
<hr align=center width="20%">
<table align=center border=1>
Create a student address details web page using table, tr, colspan, th & td tag.
<html>
<head> <title> Student address </title> </head>
<body>
<h1 align=center> <u> Siddartha Degree & PG College </u> </h1>
<table align=center border=1>
<tr> <th align=center colspan=3> Student Address </th> </tr>
<tr> <th align=center> Hno </th>
Create a student marks details web page using table, caption, tr, colspan, th & td tag.
<html>
<head> <title> Student Marks </title> </head>
<body> <h1 align=center> <u> Siddartha Degree & PG College </u> </h1>
<h3 align=center> <u> B.Com (Computer) </u> </h3>
<h4 align=center> <u> Marks List (I-Sem) for the Academic year 2017-18</u> </h4>
<table align=center border=1>
<caption> Consolidated Marks Report </caption>
<colgroup width=”30%” span=”2”> </colgroup>
<colgroup span=”3”> </colgroup>
<thead bgcolor=”blue”>
</body>
</html>
- - - - - - - - - - - -
Input element: This is most commonly used element in HTML, it is used to read the input value.
The most important form element is the input element. An input element can be of type
text field, checkbox, password, radio button, submit button and more.
Attributes are: type: It specifies the type of the field
name: It gives the name to the created field.
value: It specifies the value to the field
Text field: Defines a one-line input field that a user can enter text into this field.
Represented as, <input type=”text” />
Example: <form>
First name: <input type=”text” name=”firstname”/> <br>
Last name: <input type=”text” name=”lastname”/>
</form>
Ex: Create a web page to read input text field.
<html>
<head>
<title> Text Field </title>
</head>
<form>
<label for="username">Username:</label>
<html>
<head> <title> password </title> </head>
<form>
<label for="user-pwd">Password:</label>
<input type="password" name="user-password" id="user-pwd">
or
Password: <input type="password" name="user-password">
</form>
</html>
---- ----
Radio Buttons: Defines a radio button, Radio buttons let a user select only one, one of a limited
number of choices,
Represented as, <input type=”radio”/>
Example: <form>
<input type=”radio” name=”sex” value=”male”/> Male <br/>
<input type=”radio” name=”sex” value=”female”/> Female
</form>
Example: <form>
<input type=”checkbox” name=”vehicle” value=”Bike”/> I have a bike <br/>
<input type=”checkbox” name=”vehicle” value=”care”/> I have a car <br/>
</form>
Ex: Create a web page to insert checkbox (sports details).
<html>
<head> <title> Games </title> </head>
<form>
<input type="checkbox" name="sports" id="kabadi">
<label for="kabadi">Kabadi</label> <br>
<input type="checkbox" name="sports" id="cricket">
<label for="cricket">Cricket</label> <br>
<input type="checkbox" name="sports" id="baseball">
<label for="baseball">Baseball</label>
or
<input type="checkbox" name="sports" id="kabadi"> Kabadi <br>
<input type="checkbox" name="sports" id="cricket"> Cricket <br>
<input type="checkbox" name="sports" id="baseball"> Baseball
</form>
</html>
---- ---
File Select Box: Define a file select box. The file fields allow a user to browse for a local file
and send it as an attachment to the form data. Text box with a button that enables the user to
browse for a file. However, the user can also type the path and name of the file in the text box.
Represented as, <input type=”file” />
Ex: Create a web page to upload file.
<html>
<head> <title> fileupload </title> </head>
<form> <label for="file-select">Upload:</label>
<input type="file" name="upload" id="file-select">
or
Upload:<input type="file" name="upload">
</form>
</html> ---- ---
Textarea: Textarea is a multiple-line text input control that allows a user to enter more than one
line of text.
Represented as: <textarea> Text </textarea>
Select Boxes: A select box is a dropdown list of options that allows user to select one or more
option from a pull-down list of options. Select box is created using the <select> element
and <option> element.
Submit and Reset Buttons: A submit button is used to send the form data to a web server.
When submit button is clicked the form data is sent to the file specified in the form's action
attribute to process the submitted data. A reset button resets all the forms control to default
values.
<head>
<title> Submit Reset </title>
</head>
<body>
<form>
<form action="action.php" method="post">
File Name: <input type="text" name="first-name">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
<html>
<head>
<title>
Form1
</title>
</head>
<form>
<fieldset>
<legend>Log In</legend>
<label>Username: <input type="text"> </label>
<label>Password: <input type="password"> </label>
<input type="submit" value="Submit">
</fieldset>
</form>
</html>
Application form:
<html>
<head> <title> Form </title>
</head>
<body>
<FORM>
Name : <input type=”text” name=”cndname”> <br>
<input type="radio" name="sex"> Male
<input type="radio" name="sex"> Female <br>
FName: <input type=”text” name=”fname”> <br>
</form>
</body>
</html>
<select name="Day">
<option value="Day"> Day </option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option> 3 </option> <option> 4 </option>
<option> 5 </option> <option> 6 </option>
<option> 7 </option> <option> 8 </option>
<option> 9 </option> <option> 10 </option>
<option> 11 </option> <option> 12 </option>
<option> 13 </option> <option> 14 </option>
main.html
<body bgcolor=blue>
<h1> Main Frame </h1>
<font face=Arial size=”8” color=red>
<p> This is the Main Frame color is red and size is 8 pixels. </p>
</body>
bottom.html
<body bgcolor=green>
<h1> Bottom Frame </h1>
<font face=Arial size=”8” color=red>
<p> This is the Bottom Frame color is red and size is 8 pixels. </p>
</body>
5. Create frame1
<html><head> </head>
<body text="green" bgcolor="red">
<img src="Tulips.jpg" width="50" height="50">
<h1> <center> Welcome to my web-page </center> </h1>
</body>
</html>
6. Create frame2
<html><head> </head>
<body text="blue" bgcolor="pink">
<pre> <p><b> Home Ms-Office Java Contact
</b> </p> </pre>
</body>
</html>
7. Create frame3
<html> <head> </head>
<body bgcolor="yellow">
<b> <font size="5"> <br><br>
<a href="file:///E:/links%20frames/home.html" target="frame4">
Home </a> <br><br>
<a href="file:///E:/links%20frames/Java.html" target="frame4">
Java </a> <br><br>
<a href="file:///E:/links%20frames/msoffice.html" target="frame4">
Msoffice </a> <br><br>
<a href="file:///E:/links%20frames/contact.html" target="frame4">
Contact </a> </font> </b>
</body>
</html>
8. Create frame4
<html> <head> </head>
<body bgcolor="black"> </body>
</html>
9. Create frame5
<html> <head> </head>
<body text="yellow" bgcolor="brown">
<marquee behavior="alternate" scrollamount=10 bgcolor="blue">
<b> <u> <i> Job notification <br>
only state telangana <br>
for latest updates <br>
contact : 9441915553
</b></u></i>
</marquee>
</body>
</html>
Inline Styles:
An inline style can be to applied to individual (unique or single) elements in the Web page.
Syntax/Example:
<head> <style type=”text/css”>
body { background-color: yellow}
p { color: blue}
</style>
<head>
"mystyle.css":
body { background-color: lightblue; }
h1 { color: navy; margin-left: 20px; }
<html>
<head> <title> External </title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Embedded Style Sheet:
We can group more than one style rule using the <style> - - - </style> tag pair instead of
applying it individually in the inline style. Each of these tags when used in the body of the
HTML code will apply the style rules.
Syntax: <head> <style> Style Rules </style> </head>
style2.css
<style> h2 { background: red; }
</style>
main.css
<style> @import url (style1.css)
@import url (style2.css)
</style>
importstyle.html
<html>
<head> <title> Import style </title>
<link rel=stylesheet href=”main.css” type=”text/css”>
</head>
<body> Other Statements
</body>
</html>
---- ----
Text Formatting:
The heading uses the text-align, text-transform, and color properties. The paragraph is
indented, aligned, and the space between characters is specified.
a. Text Color: The color property is used to set the color of the text. The color is
specified by:
· A color name – like “red”
· A Hexadecimal value – like “#ff0000”
· An RGB value – like “rgb(255,0,0)
The default text color for a page is defined in the body selector.
<html>
<head>
<title> Text decoration-2 CSS </title>
<style> h1 { text-decoration: overline; }
h2 { text-decoration: line-through; }
h3 { text-decoration: underline; }
</style>
</head>
<body> <h1> Heading1 </h1>
<h2> Heading2 </h2>
<h3> Heading3 </h3>
</body>
</html>
d. Text Transformation: The text-transform property is used specify uppercase and lowercase
letters in a text.
It can be used to turn everything into uppercase or lowercase letters, or capitalize
the first letter of each word.
Ex: p.uppercase { text-transform: uppercase; }
Create a web page using text-transformation using CSS.
<!DOCTYPE html>
<html>
<head>
<title> Text transformation CSS </title>
<style> p.uppercase { text-transform: uppercase; }
p.lowercase { text-transform: lowercase; }
p.capitalize { text-transform: capitalize; }
</style>
</head> <body>
<p class=”uppercase”> This is some text. </p>
<p class=”lowercase”> This is some text. </p>
<p class=”capitalize”> This is some text. </p>
</body>
</html>
e. Text Indentation: The text-indent property is used to specify the indentation of the first line
of text.
Ex: <style> p < text-indent: 50px; } </style>
Create a web page using text-indentation using CSS.
<!DOCTYPE html>
<html> <head>
<title> Text Indentation CSS </title>
<style> p {text-indent: 50px;} </style>
</head>
<body>
<p> This text is styled with some of the text formatting properties. <br>The
heading uses the text-align, text-transform and color properties. <br>The paragraph is indented,
aligned and the space between characters <br> is specified. </p>
</body>
</html>
f. Text letter spacing: The letter-spacing property is used to specify the space between
the characters in a text.
Ex: <style> h1 { letter-spacing: 3px; } </style>
Create a web page using letter-spacing using CSS.
<!DOCTYPE html>
<html> <head> <title> Letter spacing CSS </title>
<style> h1 { letter-spacing: 3px; }
h2 { letter-spacing: -3px; } </style>
</head>
<body> <h1> This is Heading1 </h1>
<h2> This is Heading2 </h2> </body>
</html>
g. Text Line Height: The line-height property is used to specify the space between lines.
Ex: p.small { line-height: 0.8; }
p.big { line-height: 1.8; }
Create a web page using Line-Height using CSS.
<!DOCTYPE html>
<html> <head> <title> Line Height CSS </title>
<style> p.small { line-height: 0.7; } p.big { line-height: 1.8; } </style>
</head> <body>
<p> This is a paragraph with a standard line-height. <br>
The default line height in most browsers is about 110% to 120%. <br> </p>
<p class=”small”> This is a paragraph with a smaller line-height. <br>
This is a paragraph with a smaller line-height. <br> </p>
<p class=”big”> This is a paragraph with a bigger line-height. <br>
This is a paragraph with a bigger line-height. <br> </p>
</body>
</html>
h. Text Direction: The direction property is used to change the text direction of an
element.
Ex: p { direction: rtl; }
Create a web page using Text-Direction using CSS.
<!DOCTYPE html>
<html> <head> <title> Text Direction CSS </title>
<style> p.ex1 { direction: rtl;} </style>
</head>
<body> <p> This is the default text direction </p>
<p class=”ex1”>
This is the right-to-left text direction
</p>
</body>
</html>
i. Text Word Spacing: The word-spacing property is used to specify the space between
the words in a text.
Ex: h1 { word-spacing: 10px; }
Create a web page using Word-Spacing using CSS.
<!DOCTYPE html>
<html><head><title> Word Spacing CSS </title>
<style> h1 { word-spacing: 10px;}
h2 { word-spacing: -5px;}
</style>
</head>
<body> <h1> This is heading1 </h1>
<h2> This is heading1 </h2>
</body>
</html>
j. Text Shadow: The text-shadow property adds shadow to text.
Ex: h1 { text-shadow: 3px 2px; red; }
Example specify the position of the horizontal shadow (3px), the position of the vertical
shadow (2px) and the color of the shadow (red).
<!DOCTYPE html>
<html> <head> <title> Text Shadow CSS </title>
<style> h1 { text-shadow: 3px 2px red; }
</style>
</head>
<body> <h1> Text-shadow effect </h1>
<p> <b> Note: </b> Internet explorer 9 and
earlier do not <br>
support the text-shadow property. </p>
</body>
</html>
---- ----
Outlines:
An outline is a line that is drawn around elements, OUTSIDE the borders, to make the
element “standout”. CSS has the following outline.
i. outline-style ii. outline-color iii. outline-width
iv. outline-offset v. outline
i. outline-style: The outline-style property specifies the style of the outline, and can have one of
the following values.
* dotted - Defines a dotted outline * dashed - Defines a dashed outline
* solid - Defines a solid outline * double - Defines a double outline
* groove - Defines a 3D grooved outline * ridge - Defines a 3D ridged outline
* inset - Defines a 3D inset outline * outset - Defines a 3D outset outline
* none - Defines no outline * hidden - Defines a hidden outline
Ex: p.dotted {outline-style: dotted;}
p.dashed {outline-style: dashed;}
p.solid {outline-style: solid;}
p.double {outline-style: double;}
p.groove {outline-style: groove;}
p.ridge {outline-style: ridge;}
p.inset {outline-style: inset;}
p.outset {outline-style: outset;}
ii. outline-color: The outline-color property is used to set the color of the outline.
The color can be set by:
67. name - specify a color name, like "red"
68. RGB - specify a RGB value, like "rgb(255,0,0)"
69. Hex - specify a hex value, like "#ff0000"
70. invert - performs a color inversion (which ensures that the outline is visible, regardless of
color background)
iii. outline-width: The outline-width property specifies the width of the outline, and can have
one of the following values:
* thin (typically 1px) * medium (typically 3px)
* thick (typically 5px) * A specific size (in px, pt, cm, em, etc)
Ex: p.ex1 { border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: thin; }
p.ex2 { border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: medium; }
p.ex3 { border: 1px solid black; outline-style: solid; outline-color: red;
outline-width: thick; }
p.ex4 { border: 1px solid black; outline-style: solid; outline-color: red;
outline-width: 4px; }
iv. outline-offset: The outline-offset property adds space between an outline and the edge/border
of an element. The space between an element and its outline is transparent.
p { margin: 30px;
bo rder: 1px solid black;
outline: 1px solid red;
outline-offset: 15px; }
p { margin: 30px;
background: yellow;
border: 1px solid black;
outline: 1px solid red;
outline-offset: 15px; }
v. outline: The outline property is a shorthand property for setting the following individual
outline properties:
* outline-width * outline-style (required) * outline-color
The outline property is specified as one, two, or three values from the list above. The order of the
values does not matter.
Ex: p.ex1 {outline: dashed;}
p.ex2 {outline: dotted red;}
p.ex3 {outline: 5px solid yellow;}
p.ex4 {outline: thick ridge pink;}
---- ----
Learning JavaScript:
Learning JavaScript:
The script is an integral part of the HTML Document delivered to the client by the
server. It is interpreted and run within the browser application being used by the client.
Scripting Language is the language which is used to implement the programming
language features to the browser executable programs.
Basically there are two types of Scripting Languages.
39. Client Side Scripting Language
40. Server Side Scripting Language
Client side Java Script: The program which is written and implemented in the client
side PC is considered as Client side Scripting Language. Example: VB Script, Java
Script.
Server side Java Script: The script code which is written and executed in the Server but
the output is visible in the client considered as Server side Scripting Language. Example:
ASP (Active Server Pages), CGI (Common Gate Way of interface).
Application of JavaScript:
JavaScript is used to create interactive websites. It is mainly used for:
71. Client-side validation
72. Dynamic drop-down menus
73. Displaying date and time
74. Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog
box and prompt dialog box)
75. Displaying clocks etc.
Note:
The script tag specifies that we are using JavaScript.
The text/javascript is the content type that provides information to the browser about the data.
The document.write() function is used to display dynamic content through JavaScript. We will
learn about document object in detail later.
<html>
<head> <title> Java Script </title>
<script>
document.write("welcome to JavaScript");
</script>
</head>
<body>
</body>
</html>
JavaScript Example2:
<html>
<head> <title> Java Script </title>
<script>
document.write("<h1> SDPC </h1>"+”<br>”);
document.write("welcome to JavaScript");
</script>
</head>
<body> <h2> This is a first java script in HTML </h2>
</body>
</html>
Variables:
Variable is simply a name of storage location. There are two types of variables in
JavaScript: local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as identifiers).
44. Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
45. After first letter we can use digits (0 to 9), for example value1.
46. JavaScript variables are case sensitive, for example x and X are different variables.
Correct JavaScript variables
var x = 10; var _value="nalgonda";
Incorrect JavaScript variables
var 123=30; var *aa=320;
<html>
<head> <title> Java Script (Add two numbers) </title> </head>
<body> <script>
var x = 10,y = 20,z;
z=x+y;
document.write(x + "+" + y + "=" + z);
</script>
</body>
</html>
* Program to find area of the circle.
<html> <head> <title> Java Script </title>
<script> var r=1,a;
a=3.14*r*r;
document.write("area of the circle:"+a);
</script>
</head>
<body> </body>
</html>
* Program to swap two numbers:
<html>
+ Addition 10+20 = 30
- Subtraction 20-10 = 10
/ Division 20/10 = 2
% Modulus 20%10 = 0
(Remainder)
Comparison (Relational) Operators: The JavaScript comparison operator compares the two
operands. The comparison operators are as follows:
Op Description Example
era
tor
Bitwise Operators: The bitwise operators perform bitwise operations on operands. The bitwise
operators are as follows:
Op Description Example
era
tor
| Bitwise OR
^ Bitwise XOR
Logical Operators: The following operators are known as JavaScript logical operators.
Op Descrip Example
era tion
tor
Assignment Operators: The following operators are known as JavaScript assignment operators.
Op Description Example
era
tor
= Assign 10+10 = 20
Special Operators: The following operators are known as JavaScript special operators.
Op Description
era
tor
(?:) Conditional Operator returns value based on the condition. It is like if-
else.
* Program to add, subtract, multiply, divide and find remainder of the two numbers.
if-else if statement: It evaluates the content only if expression is true from several expressions.
Syntax: if(expression1)
{ //content to be evaluated if condition is true
}
else if(expression2)
{ content to be evaluated if expression2 is true
}
else
{ content to be evaluated if expression2 is true
}
Write a JavaScript to check the number is positive, negative or zero.
<html> <head> <title> If-else statement </title>
Functions:
Def: - Sub program.
Function is sub program. It having own name and block of statements. When it is called
from main it will be executed.
main
function
function
function
</script>
</head>
<body>
<input type="button" onclick="display()" value="call function"/>
</body>
</html>
}
</script> </head>
<body> <form>
<input type="button" value="click" onclick="getcube(4)"/>
</form> </body>
</html>
f = f * i;
alert(f);
}
</script> </head>
<body> <form>
<input type="button" value="fact" onclick="factor(5)">
</form> </body>
</html>
Write a JavaScript to find cube of the number using passing by arguments and return type.
<html> <head> <title> Factorial </title>
<script> function factor(n)
{ var i,f=1;
for(i=1;i<=n;i++)
f = f * i;
return f;
}
</script> </head>
<body> <script>
document.write(factor(5));
</script> </body>
</html>
Array:
JavaScript array is an object that represents a collection of similar type of elements.
There are 3 ways to construct array in JavaScript
53. By array literal
54. By creating instance of Array directly (using new keyword)
55. By using an Array constructor (using new keyword)
1) JavaScript array literal
The syntax of creating array using array literal is given below:
var arrayname=[value1,value2.....valueN];
As you can see, values are contained inside [ ] and separated by , (comma).
Simple example of creating and using array in JavaScript.
<html> <head> <title> Java Script </title>
<script>
var x=[10,20,30,40,50],i;
for (i=0;i<=4;i++)
{ document.write(x[i] + "<br>");
}
</script> </head> <body> </body>
</html>
Test it Now
Let's see the list of JavaScript array methods with their description.
S. Metho Description
N ds
o
1 concat( It returns a new array object that contains two or more merged arrays.
)
2 copywi It copies the part of the given array with its own elements and returns the
thin() modified array.
3 every() It determines whether all the elements of an array are satisfying the
provided function conditions.
5 filter() It returns the new array containing the elements that pass the provided
function conditions.
6 find() It returns the value of the first element in the given array that satisfies the
specified condition.
7 findInd It returns the index value of the first element in the given array that satisfies
ex() the specified condition.
8 forEac It invokes the provided function once for each element of an array.
h()
9 include It checks whether the given array contains the specified element.
s()
10 indedx It searches the specified element in the given array and returns the index of
Of() the first match.
12 lastInd It searches the specified element in the given array and returns the index of
exOf() the last match.
13 map() It calls the specified function for every array element and returns the new
array
18 slice() It returns a new array containing the copy of the part of the given array.
21 unshift It adds one or more elements in the beginning of the given array.
()
<html>
<head> <title> Event Handling </title> </head>
<body onmousedown=”document.bgColor=’red’”;
onmouseup=”document.bgColor=’blue’”;
onclick=”document.bgColor=’green’”>
<center> <h1> See the page in red when mouse down
<br> <br>
And in blue when up <br> <br>
In green when clicked. <br> <br>
</h1> </center> </body>
</html>
ii. Changing Font properties dynamically: All the font properties which are used in style
sheet can be implemented with event handlers and DOM methods which help the user to change
the properties dynamically.
Ex:
<html>
<head> <title> Event Handling </title> </head>
<body> <center> <h1 onmouseover=”this.style.fontSize =’48’”;
onmouseout=”this.style.fontSize =’18’”>
Changing the font size move the mouse and see the changes <br> <br>
</h1> </center> </body>
</html>
iii. Effecting multiple changes: Changing the font size color and family on mouse over, style
classes are used. All the properties are combined with in a single class defined by the user and
the class is called with Event handling methods.
Ex:
<html> <head> <title> Event Handling </title>
<style type=text/css>
.c1 {font-size: 85; color:red; font-family:Monotype Corsiva}
.c2 {font-size: 35; color:blue; font-family:Harlow Solid Italic; border:30}
</style> </head>
<body> <center> <h1 onmouseover=”this.className =’c1’”;
onmouseout=”this.className =’c2’”>
Changing the font size move the mouse and see the changes <br> <br>
</h1> </center> </body>
</html>
iv. Changing the images on fly: Change the image itself in runtime by using the DOM
methods. This can be performed by two methods 1. Event handling 2. Script method.
Ex: 1. Event handling method
<html> <head> <title> Event handling </title> </head>
<body> <center>
<img src=”2.jpg” height=500 width=500
onmouseover=”this.src=’1.jpg’”
onmouseout=”this.src=’3.jpg’”>
</center> </body>
</html>
Ex: 2. Script method.
<html> <head> <title> Event handling </title>
<script language=”vbs”>
sub swap
document.i1.src=”2.jpg”
document.i2.src=”1.jpg”
end sub
</script> </head>
<body> <center> <h1> Using Script procedures & Event </h1> <br> <br>
<img src=”1.jpg” height=200 width=200 id=”i1”>
<img src=”2.jpg” height=200 width=200 id=”i2”> <br>
<input type=button value=swapping onclick=swap>
</center> </body>
</html>
Events: Event is a object which describes a state change in a source.
Eg: Pressing or clicking button, click on event, closing window, resizing window, image has
been loaded, dragging a mouse, mouse over an element, . . . . etc.
It is two types.
56. Reactive event - User involvement.
57. Proactive event - No user involvement.
Events are a part of Document Object Model (DOM) and html element have a certain set
of events which can trigger JavaScript code.
OnClick: The onClick event occurs when the user clicks on an element.
<button onclick=”myFunction( )”> click me </button>
</script> </head>
<body>
<input type="button" onclick="myFunctipon( )" value="call function"/>
</body>
</html>
Ondbl click: The ondbl click event occurs when the user double click on an element.
Ex: In JavaScript <p ondblclick=”myFunction( )”> Double-click me </p>
In HTML <element ondblclick=”myScript”>
object.ondblclick=function( ) { myScript };
object.addEventListener(“dblclick”,myScript);
OnAbort:
The OnAbort event occurs when user aborts the loading of an <img> or
<input type=”image”> element.
Ex: <img src=”3.jpg” onabort=”myFunction( )”>
Syntax: In HTML <element onabort=”myScript”>
In JavaScript object. onabort=function( )
{ myScript };
In JavaScript, using the addEventListener(“abort”, myScript);
Note: The addEventListener( ) method is not supported in Internet Explorer 8 and earlier
versions.
Ondrag drop: The ondrag drop event occurs when the user drag and drop an element.
58. ondragenter – occurs when the dragged element enters the drop target.
59. ondragover – occurs when the dragged element is over the drop target.
60. ondragleave – occurs when the dragged element leaves the drop target.
61. ondrop – occurs when the dragged element dropped on the drop target.
62. ondragstart – occurs when the user starts to drag an element.
63. ondrag – occurs when an element is being dragged.
64. ondragend – occurs when the user has finished dragging the element.
Onerror: The onerror event occurs when loading a image or error occurs while loading an
external file (e.g. a document or image).
Ex: <img src=”image.jpg” onerror=”myFucntion( )”>
Onfocus: The onfocus attribute fires the moment that the element gets focus.
Onfocus is most often used with <input>, <select> and <a>.
Ex: <input type=”text” id=”fname” onfocus=”myFucntion(this.id)”>
Onkey Press: The onkeypress event occurs when the user presses a key (on the keyboard).
Note: The onkeypress event is not fired for all keys (e.g. Alt, ctrl, shift, esc) in all browsers.
onkeypress event:
i. onkeydown ii. Onkeypress iii. onkeyup
Ex: <input type=”text” onkeypress=”myFucntion( )”>
}
</script> </body>
</html>
Onload: The onload attribute fires when an object has been loaded.
Onload most often used within the <body> element to execute a script once a web page
has completely loaded all content (including images, script files, CSS files, etc..)
Syntax: In HTML : <element onload=”scropt”>
In JavaScript : <body onload=”myFunction( )”>
Onmouse Down: The Onmouse Down attribute fires when a mouse button is pressed down on
the element.
Attributes: i. onmousedown ii. onmouseup iii. oncontextmenu
Syntax: <element onmousedown=”script”>
Ex: <p onmousedown=”moseDown( )”> click the text! </p>
Onmouse Move: The onmousemove event occurs when the pointer is moving while it is over
an element.
Ex: <div onmousemove=”myFucntion( )”> Move the Cursor Over me </div>
Syntax: In HTML : <element onmousemove=”myScript”>
In JavaScript : object.onmousemove=function( ) { myScript };
In JavaScript, using the : object.addEventListener(“mousemove”,myScript);
addEventListener( ) method
Onmouse Out: The onmouseout event occurs when the mouse pointer is moved out of an
element. This event is often used together with the onmouseover event.
Ex: <img onmouseout=”normalImg(this)” src=”1.jpg” alt=”Img”>
Syntax: In HTML : <element onmouseout=”myScript”>
In JavaScript : object.onmouseout=function( ) { myScript };
In JavaScript, using the : object.addEventListener(“mouseout”,myScript);
addEventListener( ) method
Onmouse Over: The onmouseover event occurs when the mouse pointer is moved onto an
element. This event is often used together with the onmouseout event.
Ex: <img onmouseover=”bigImg(this)” src=”1.jpg” alt=”Img”>
Syntax: In HTML : <element onmouseover=”myScript”>
In JavaScript : object.onmouseover=function( ) { myScript };
Onmove: The onmove event occurs when the pointer is moving while it is over an element.
Ex: <div onmousemove=”myFucntion( )”> Move the Cursor Over me </div>
Syntax: In HTML : <element onmousemove=”myScript”>
In JavaScript : object.onmousemove=function( ) { myScript };
In JavaScript, using the : object.addEventListener(“mousemove”,myScript);
addEventListener( ) method
Onselect: The onselect event occurs after some text has been selected in an element.
The onselect event is mostly used on <input type=”text”> or <textarea> elements.
Ex: <input type=”text” onselect=”myFunction( )”>
Syntax: In HTML : <element onselect=”myScript”>
In JavaScript : object.onselect=function( ) { myScript };
In JavaScript, using the : object.addEventListener(“select”,myScript);
addEventListener( ) method
Onunload: The onunload event occurs once a page has unloaded (or the browser window has
been closed).
Onunload occurs when the user navigates away from the page (by clicking on a link,
submitting a form, closing the browser window, etc.)
Note: The onunload events is also triggered when a user reloads the page (and the onload event).
Ex: <body onunload=”myFunction( )”>
------- --------