Web Notes MCA (Full)
Web Notes MCA (Full)
HTML stands for Hyper Text Markup Language. It is used to design web pages using markup
language. HTML is the combination of Hypertext and markup language.
● Hypertext defines the link between the web pages.
● Markup language is used to define the text document within tag which defines the
structure of web pages.
This language is used to annotate (make notes for the computer) text so that a machine can
understand it and manipulate text images and other content to display it in required format. Most
of markup (e.g. HTML) languages are human readable. Language uses tags to define what
manipulation has to be done on the text. It was created by Tim Berners-Lee in 1991.
HTML Attributes
An attribute is a property name used to provide supplementary information about HTML
elements. Some common examples of HTML attributes are id, class, align, etc. Many attributes
are defined globally and are applied to any element, whereas we use some of them only for
specific HTML elements.
You can define an attribute as the characteristics of any HTML tag that needs to be placed within
the opening tag.
HTML attributes consist of two parts:
● a name and
● a value
Html Elements
<!DOCTYPE> Tag
On the HTML document you have often seen that there is a <!DOCTYPE html> declaration
before the <html> tag. It is used to inform the browser about the version of HTML used in the
document. It is called as the document type declaration (DTD).
Technically <!DOCTYPE > is not a tag/element, it just an instruction to the browser about the
document type. It is a null element which does not contain the closing tag, and must not include
any content within it.
<HTML> Tag
It is the root of the html document which is used to specify that the document is html. This tag
tells the browser that this is an HTML document.
The <HTML> tag is the container for all other HTML elements (except for the
<!DOCTYPE> tag). Practically <HTML> is the first tag in an HTML page and </HTML> is the
last tag.
Attribute Description
2. DIR Gives the direction of directionally neural text. Possible values LTR and RTL.
3. ID Unique alphanumeric identifier for the tag, which can be used to refer it.
5. VERSION Version of the language is used. Now the version is stored in the <!DOCTYPE>
tag
6. XMLS Declares a namespace for custom tags in an HTML document. Attribute name can
be assigned to group.
<HEAD> Tag
It contains the head of an HTML document, which holds information about the document such as
its title. Once we opened this tag then we must close it as </HEAD>.
<TITLE> Tag
The <TITLE> tag is required in all HTML documents and it defines the title of the document. It
defines a title in the browser toolbar. That provides a title for the page when it is added to
favorites and displays a title for the page in search-engine results. It also has a closing tag
</TITLE>.
<BODY> Tag
The HTML <BODY> tag is used for indicating the main content section of the HTML
document. This tag defines the document's body. It contains all the contents of an HTML
document such as text, hyperlinks, images, tables, lists, etc. Once <BODY> tag is opened, it
must be closed </BODY> before the closing of </HTML> tag.
9. scroll Yes or No Specifies whether a vertical scrollbar appears to the right of the
document
Heading Tags
Headings are defined with the <H1> to <H6> tags. <H1> defines the most important heading.
<H6> defines the least important heading.
Eg: <H1> Heading </H1>
Superscript Tag<SUP>
<SUP> element, is shown in superscript Eg: <SUP>text</SUP>
Subscript Tag<SUB>
<SUB> element, is shown in subscript Eg: <SUB>text</SUB>
<HR> Tag
The <HR> tag in HTML stands for horizontal rule and is used to insert a horizontal rule or a
thematic break in an HTML page to divide or separate document sections. It is an empty tag and
it does not require an end tag.
noshade Noshade Removes the usual shading effect that most browsers display.
<IMG> Tag
The <IMG> tag is used to insert an image into a document. In HTML the
<IMG> tag has no end tag.
Attribute Value Description
Align top, bottom, middle, left, Specifies the alignment for the image.
right
List Tags
HTML offers web authors three ways for specifying lists of information. All
lists must contain one or more list elements. Lists may contain
An unordered list starts with the <UL> tag. Each list item starts with the
<LI> tag. The list items are marked with bullets i.e. small black circles by
default. Both require an end tag. </LI> and </UL>.
Eg:
<UL type=circle>
<LI>Coffee</LI>
<LI>Tea</LI>
<LI>Milk</LI>
</UL>
An ordered list starts with the <OL> tag. Each list item starts with the <LI> tag. The
list items will be marked with numbers by default. Both require an end tag. </LI> and
</OL>.
type="I" The list items will be numbered with uppercase roman numbers
type="i" The list items will be numbered with lowercase roman numbers
Eg:
<OL type=”1”>
<LI>Coffee</LI>
<LI>Tea</LI>
<LI>Milk</LI>
</OL>
<DL> Definition List
A description list is a list of terms, with a description of each term. Definition List makes
use of following three tags.
Eg:
<DL>
<DT>Coffee</DT>
</DL>
Nested List
A nested list or a sublist is a list within a list. The trick to marking nested lists up correctly in
HTML is to recognize that the sublist is actually a child of a list item and not of a list.
Eg: <!DOCTYPE html>
<html>
<body>
Linking Same Page and different pages using Relative and Absolute Pathname
Absolute URLs vs. Relative URLs
absolute URL (a full web address) in the href attribute.
A local link (a link to a page within the same website) is specified with a relative URL (without
the "[Link] part)
Eg:
<h2>Absolute URLs</h2>
<p><a href="[Link]
<p><a href="[Link]
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/[Link]">CSS Tutorial</a></p>
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
Simple Selectors
The CSS element Selector
The element selector selects HTML elements based on the element name.
Eg:
p{
text-align: center;
color: red;
}
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique
element!
To select an element with a specific id, write a hash (#) character, followed by the id of the
element.
Syntax :
#para1 {
text-align: center;
color: red;
}
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>
.center {
text-align: center;
color: red;
}
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
HTML elements can also refer to more than one class.
Eg: <p class="center large"> This paragraph refers to two classes. </p>
You can also specify that only specific HTML elements should be affected by a class.
Eg:
[Link] {
text-align: center;
color: red;
}
The CSS Universal Selector
The universal selector (*) selects all HTML elements on the page.
Eg:
*{
text-align: center;
color: blue;
}
<!DOCTYPE html>
<html>
<head>
<style>
*{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
The CSS Grouping Selector
The grouping selector selects all the HTML elements with the same style definitions.
Look at the following CSS code (the h1, h2, and p elements have the same style definitions)
h1 {
text-align: center;
color: red;
}
h2 {
text-align: center;
color: red;
}
p{
text-align: center;
color: red;
}
h1, h2, p {
text-align: center;
color: red;
}
CSS Colors
CSS allows for a variety of color formats to style web content. Here are the types of color
formats you can use in CSS:
Hexadecimal (Hex): Uses a hash symbol followed by three or six digits representing the red,
green, and blue components. For example, #ff0000 for red.
RGB: Stands for Red, Green, and Blue. Colors are defined using the rgb(red, green, blue)
format, where each value is between 0 and 255.
RGBA: Similar to RGB but adds an alpha channel for opacity, defined as rgba(red, green, blue,
alpha). The alpha value ranges from 0 (transparent) to 1 (opaque).
HSL: Stands for Hue, Saturation, and Lightness. It’s written as hsl(hue, saturation%,
lightness%), with hue as an angle between 0 and 360 degrees, and saturation and lightness as
percentages.
HSLA: Just like HSL but includes an alpha channel for opacity, formatted as hsla(hue,
saturation%, lightness%, alpha).
Named Colors: CSS supports named colors like red, green, blue, which are predefined in all
modern browsers.
Color Keywords: CSS3 introduced keywords like transparent and currentColor, which represent
a fully transparent color and the current color of an element, respectively.
h1 {
color: green;
}
Text Color and Background Color
In this example, we define both the background-color property and the color property.
body {
background-color: lightgrey;
color: blue;
}
h1 {
background-color: black;
color: white;
}
div {
background-color: blue;
color: white;
}
TEXT DECORATION
Text decoration is used to add or remove decorations from the text.
Text decoration can be underline, overline, line-through or none.
Syntax:
body
{
text-decoration:decoration type;
}
Eg:
<html>
<head>
<style>
h1
{
color:red;
text-decoration:underline;
}
</style>
</head>
<body>
<h1>
HELLO WORLD
</h1>
<h2>
TEXT FORMATTING
</h2>
</body>
</html>
TEXT TRANSFORMATION
Text transformation property is used to change the case of text, uppercase or lowercase.
Text transformation can be uppercase, lowercase or capitalize.
Capitalize is used to change the first letter of each word to uppercase.
Syntax:
body
{
text-transform:type;
}
Eg:
<!DOCTYPE html>
<html>
<head>
<style>
h2
{
text-transform:lowercase;
}
</style>
</head>
<body>
<h1>
HELLO WORLD
</h1>
<h2>
TEXT FORMATTING
</h2>
</body>
</html>
TEXT INDENTATION
Text indentation property is used to indent the first line of the paragraph.
The size can be in px, cm, pt.
Syntax:
body
{
text-indent:size;
}
Eg: <!DOCTYPE html>
<html>
<head>
<style>
h2
{
text-indent:80px;
}
</style>
</head>
<body>
<h1>
HELLO WORLD
</h1>
<h2>
This is text formatting properties.<br>
Text indentation property is used to indent the first line of the paragraph.
</h2>
</body>
</html>
LETTER SPACING
This property is used to specify the space between the characters of the text.
The size can be given in px.
Syntax:
body
{
letter-spacing:size;
}
<!DOCTYPE html>
<html>
<head>
<style>
h2
{
letter-spacing:4px;
}
</style>
</head>
<body>
<h1>
HELLO WORLD
</h1>
<h2>
This is text formatting properties.
</h2>
</body>
</html>
LINE HEIGHT
This property is used to set the space between the lines.
Syntax:
body
{
line-height:size;
}
<!DOCTYPE html>
<html>
<head>
<style>
h2
{
line-height:40px;
}
</style>
</head>
<body>
<h1>
HELLO WORLD
</h1>
<h2>
This is text formatting properties.<br>
This property is used to set the space between the lines.
</h2>
</body>
</html>
h2 {
text-align: left;
}
h3 {
text-align: right;
}
When the text-align property is set to "justify", each line is stretched so that every line has equal
width, and the left and right margins are straight (like in magazines and newspapers):
div {
text-align: justify;
}
Syntax:
The CSS element syntax is Selector
{
Declaration; /*property:value; Declaration; /*property:value*/
}
The selector points to the HTML element you want to style.
The declaration block contains one or more declarations separated by semicolons.
Each declaration includes a property name and a value, separated by a colon.
A CSS declaration always ends with a semicolon, and declaration groups are surrounded by
curly braces
Inline Style Sheet:
An inline style can be used if a unique style is to be applied to one single occurrence of an
element
To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any
CSS property
Example:
<html>
<body style="background-color:yellow;">
<h2 style="background-color:red;">This is a heading</h2>
<p style="background-color:green;">This is a paragraph.</p>
</body>
</html>
Internal Style Sheet:
An internal style sheet can be used if one single document has a unique style.
Internal styles are defined in the <head> section of an HTML page, by using the <style> tag
<style> tag comes under the head tag. It is a paired tag
Syntax:
<head>
<style>
Selector
{
Declaration; /*property:value*/ Declaration; /*property:value*/
}
</style>
</head>
Example:
<html>
<head>
<style>
body {
background-color:pink;
}
p{
color:blue;
}
</style>
</head>
<body>
I am Jahnavi. This is Internal Style sheet
<p> Cascading Style Sheets </p>
</body>
</html>
External Style Sheet
An external style sheet is ideal when the style is applied to many pages.
With an external style sheet, you can change the look of an entire Web site by changing one file.
Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the
<head> section
An external style sheet can be written in any text editor. The file should not contain any html
tags. The style sheet file must be saved with a .css extension
Syntax:
<head>
<link rel="stylesheet" type="text/css" href="[Link]">
</head>
Example:
/* This is an external style sheet file. Save this file as [Link]*/
p
{
color: yellow;
}
h2
{
color: red;
text-align: left; font-size: 8pt;
}
The CSS box model is a container that contains multiple properties including borders, margin,
padding, and the content itself. It is used to create the design and layout of web pages. It can be
used as a toolkit for customizing the layout of different elements. The web browser renders every
element as a rectangular box according to the CSS box model. Box-Model has multiple
properties in CSS. Some of them are given below:
● content: This property is used to displays the text, images, etc, that can be sized using
the width & height property.
● padding: This property is used to create space around the element, inside any defined border.
● border: This property is used to cover the content & any padding, & also allows to set the
style, color, and width of the border.
● margin: This property is used to create space around the element ie., around the border area.
● Content Area: This area consists of content like text, images, or other media content. It is
bounded by the content edge and its dimensions are given by content-box width and height.
● Padding Area: It includes the element’s padding. This area is actually the space around the
content area and within the border-box. Its dimensions are given by the width of the
padding-box and the height of the padding-box.
● Border Area: It is the area between the box’s padding and margin. Its dimensions are given
by the width and height of the border.
● Margin Area: This area consists of space between border and margin. The dimensions of the
Margin area are the margin-box width and the margin-box height. It is useful to separate the
element from its neighbors.
Eg:
<!DOCTYPE html>
<head>
<title>CSS Box Model</title>
<style>
.main {
font-size: 36px;
font-weight: bold;
Text-align: center;
}
.gfg {
margin-left: 60px;
border: 50px solid #009900;
width: 300px;
height: 200px;
text-align: center;
padding: 50px;
}
.gfg1 {
font-size: 42px;
font-weight: bold;
color: #009900;
margin-top: 60px;
background-color: #c5c5db;
}
.gfg2 {
font-size: 18px;
font-weight: bold;
background-color: #c5c5db;
}
</style>
</head>
<body>
<div class="main">CSS Box-Model Property</div>
<div class="gfg">
<div class="gfg1">GeeksforGeeks</div>
<div class="gfg2">
A computer science portal for geeks
</div>
</div>
</body>
</html>
Creating a table
<table> tag
An HTML table is defined with the <TABLE> tag. Each table row is defined with the
<TR>tag. A table header is defined with the <TH> tag. By default, table headings are
bold and centered. A table data/cell is defined with the <TD>tag.
Attribute Value Description
<TH> Tag
The <TH> tag defines a header cell in an HTML table. An
● Header cells - contains header information (created with the <TH> element)
● Standard cells - contains data (created with the <TD>
Colspan Number Specifies the number of columns the header cell spans
across.
Rowspan Numbers Specifies the number of rows the header cell spans across.
<TR> Tag
The <TD> tag defines a standard cell in an HTML [Link] HTML table has two kinds
of cells:
● Header cells - contains header information (created with the <TH> element)
● Standard cells - contains data (created with the <TD> element)The text in
<TH> elements is bold and centered by default. The text in <TD> elements is
regular and left-aligned by default.
Eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MCA Timetable</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
.lunch {
background-color: #e0e0e0;
}
</style>
</head>
<body>
<h2>MCA Course Timetable</h2>
<table>
<tr>
<th>Day / Time</th>
<th>9:00 - 10:00</th>
<th>10:00 - 11:00</th>
<th>11:00 - 12:00</th>
<th>12:00 - 13:00</th>
<th>13:00 - 14:00</th>
<th>14:00 - 15:00</th>
<th>15:00 - 16:00</th>
<th>16:00 - 17:00</th>
</tr>
<tr>
<th>Monday</th>
<td>Subject 1</td>
<td>Subject 2</td>
<td>Subject 3</td>
<td>Subject 4</td>
<td class="lunch" rowspan="5">Lunch Break</td>
<td colspan="3">Lab</td>
</tr>
<tr>
<th>Tuesday</th>
<td>Subject 6</td>
<td>Subject 7</td>
<td>Subject 8</td>
<td>Subject 9</td>
<td colspan="3">Lab</td>
</tr>
</table>
</body>
</html>
When you add a border to a table, you also add borders around each table cell:
To add a border, use the CSS border property on table, th, and td elements:
Eg:
table, th, td {
border: 1px solid black;
}
To avoid having double borders like in the example above, set the CSS border-collapse property
to collapse.
Eg:
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
Style Table Borders
If you set a background color of each cell, and give the border a white color (the same as the
document background), you get the impression of an invisible border:
table, th, td {
border: 1px solid white;
border-collapse: collapse;
}
th, td {
background-color: #96D4D4;
}
Round Table Borders
With the border-radius property, the borders get rounded corners:table, th, td {
border: 1px solid black;
border-radius: 10px;
}
With the border-style property, you can set the appereance of the border.
● dotted
● dashed
● solid
● double
● groove
● ridge
● inset
● outset
● none
● hidden
eg:
th, td {
border-style: dotted;
}
Border Color
With the border-color property, you can set the color of the border.
Eg:
th, td {
border-color: #96D4D4;
}
Creating Forms
HTML Forms are required, when you want to collect some data from the site visitor.
For example, during user registration you would like to collect information such as
name, email address, credit card, etc. An HTML form contains form elements.
A form will take input from the site visitor and then will post it to a back-end
application such as CGI, ASP Script or PHP script etc. The back-end application will
perform required processing on the passed data based on defined business logic inside
the application
. Then your back-end application will do required processing on that data in whatever way you
like. Form elements are like text fields, text area fields, drop-down menus, radio buttons,
checkboxes, etc. which are used to take information from the user.
A simple syntax of using <form> is as follows:
<form action="back-end script" method="posting
method">form elements like input, textarea etc.
</form>
The various form attributes are:
● name: This is the name of the form.
● action: Here you will specify any script URL which will receive uploaded data.
● method: Here you will specify method to be used to upload data. It can take various
values but most frequently used are GET and POST.
The get method sends the data captured by form elements to the web server encoded into a
URL, which points to a web server. The data is appended to the URL. This method is used
when the amount of data sent to the web server is small. This is the default method used
The post method sends the data captured by form elements to the web server as a separate bit
stream of data. This method is used when the amount of data sent to the web server is large.
target: It specifies the target page where the result of the script will be displayed. It
takes values like _blank, _self, _parent etc.
<FORM> Tag
The HTML <FORM> element defines a form that is used to collect user input:
The <label> element is useful for screen-reader users, because the screen-reader will read out
loud the label when the user focus on the input element.
The <label> element also help users who have difficulty clicking on very small regions (such as
radio buttons or checkboxes) - because when the user clicks the text within the <label> element,
it toggles the radio button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of the <input> element to
bind them together.
<!DOCTYPE html>
<html>
<body>
<form>
</form>
<p>Also note that the default width of text input fields is 20 characters.</p>
</body>
</html>
<INPUT> Tag
The <INPUT> tag is used within a <FORM> element to declare input controls that
allow users to input data.
An input field can vary in many ways, depending on the type attribute. The <INPUT>
element is empty, it contains attributes only
Value Text Specifies the intial value for the [Link] type
= "checkbox" or type = "radio" this attribute is
required.
In HTML <INPUT TYPE=" "> is an important element of HTML form. The "type" attribute of
input element can be various types, which defines information field. Such as <INPUT
TYPE="text" NAME="name"> gives a text box.
Description
<INPUT TYPE=" ">
● <input type="button">
● <input type="checkbox">
● <input type="password">
● <input type="radio">
● <input type="reset">
● <input type="submit">
● <input type="text">
Eg:
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
First name: <br>
<input type = "text" name = "first_name" /><br> Last name:
<br>
<input type = "text" name = "last_name" />
</form>
</body>
</html>
HTML Forms –
Example:
<html>
<body>
<form action="/cgi-bin/hello_get.cgi" method="get"> First
name:
<input type="text" name="first_name" />
<br>
Last name:
<input type="text" name="last_name"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
Following is the list of attributes for <input> tag.
● type: Indicates the type of input control you want to create. This element is also used to create
other form controls such as radio buttons and checkboxes.
● name: Used to give the name part of the name/value pair that is sent to the server, representing
each form control and the value the user entered.
● value: Provides an initial value for the text input control that the user will see when the form
loads.
● size: Allows you to specify the width of the text-input control in terms of characters.
● maxlength: Allows you to specify the maximum number of characters a user can enter into the
textbox.
<title>Login Page</title>
</head>
<body>
<form action="" method="get">Login :
<input type="text" name="login" />
<br> Passwod:
<input type="password" name="password" /><br>
<input type="reset" value="reset" />
</form>
</body>
</html>
When you use the <input> element to create a button, the type of button you create is specified using the
type attribute. The type attribute can take the following values:
● submit: This creates a button that automatically submits aform.
● reset: This creates a button that automatically resets form controls to their initial values.
● button: This creates a button that is used to trigger a client-side script when the user clicks that
button.
Example:
<html>
<body>
<form action=" " method="get">
<input type="submit" name="Submit" value="Submit" />
<br /><br />
<input type="reset" value="Reset" />
<input type="button" value="Button"/>
</form>
</body>
</html>
Output
HTML Forms - Checkboxes Control:
Checkboxes are used when more than one option is required to be selected. They are created using
<input> tag as shown below.
Following is the list of important checkbox attributes:
● type: Indicates that you want to create acheckbox.
● name: Name of the control.
● value: The value that will be used if the checkbox is selected. More than one checkbox should
share the same name only if you want to allow users to select several items from the same list.
● checked: Indicates that when the page loads, the checkbox should beselected.
Example:
<html>
<body>
<form action=" " method="get"> Select your hobbies from the
list <br>
<input type="checkbox" name="Cricket" value="on"> Cricket<br>
Output
HTML Forms - Radio box Control:
Radio Buttons are used when only one option is required to be selected. They are created using
<input> tag as illustrated below.
Following is the list of important radiobox attributes:
● type: Indicates that you want to create a radiobox.
● name: Name of the control.
● value: Used to indicate the value that will be sent to the server if this option isselected.
● checked: Indicates that this option should be selected by default when the pageloads.
Example:
<html>
<body>
<form action=" " method="post">
<input type="radio" name="gender" value="Male" /> Male <br>
<input type="radio" name="gender" value="Female" /> Female<br>
<input type="submit" value="Select Gender" />
</form>
</body>
</html>
Output
Example:
<html>
<body>
<form action=" " method="post">
<select name="dropdown">
<option value="Maths" selected>Maths</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
</select>
<input type="submit" value="Submit" />
</form>
</body>
</html>
Example:
<html>
<body>
<form action="" method="post" name="fileupload"
enctype="multipart/form-data">
<input type="file" name="fileupload" accept="image/*" />
</form>
</body>
</html>
Output:
Introduction to JavaScript and jQuery :The Basics of JavaScript: Overview of JavaScript, Object
Orientation and JavaScript, General Syntactic Characteristics- Primitives, Operations, and Expressions, Screen
Output and Keyboard Input, Control Statements, Object Creation and Modification, Arrays, Functions. Callback
Functions, Java Script HTML DOM.
JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as
Internet Explorer, Mozilla, Firefox, Netscape, Opera.
Overview of JavaScript
ORIGIN
Now standardized by the European Computer Manufacturers Association as ECMA-262 (also ISO 16262)
1) Core Javascript - Heart of the language , including its operators, expressions, statements and
subprogram.
2) Client-side JavaScript - Collections of JavaScript code scripts , not programs, support the control
of browsers and interaction with the user
3) Server side Javascript - Collection of objects that make the language useful on a web server.
• Java (developed by Sun Microsystems) is a powerful and much more complex programming
language - in the same category as C and C++.
• Object model of Javascript is quite different from java & C++.
• In Java ,types are all known at compile time, where as in Javascript variables need not be
declared and compile time type checking impossible.
• Either directly, as in
<script type = "text/javaScript">
</script>
Or indirectly, as a file specified in the src attribute of <script>, as in
</script>
Identifier form: begin with a letter or underscore, or dollar sign ($) followed by any number of
letters, underscores, and digits
• Case sensitive
• Scripts are usually hidden from browsers that do not support JavaScript interpreters by
<!--
-- JavaScript script –
//-->
The interpreter will insert a semicolon after return, because return need not be followed by an expression,
making x an invalid orphan.
To avoid this problem, put each statement on its own line and terminate each statement with a
semicolon.
//[Link]
<!DOCTYPE html>
<html lang=“EN”>
</head>
<body>
<script type="text/javascript">
[Link]("Hello World!");
</script>
</body>
</html>
[Link] Types
Five primitive types: Number, String, Boolean, Undefined, or Null.
Javascript includes predefined objects that are closely related to primitive types named Number ,string and
Boolean. These objects are called wrapper objects. Because each objects contains a property that stores a value
of the corresponding primitive type. The purpose of Wrapper objects are used to provide properties and
methods that are convenient to use with the values of primitive types. Javascript coerces values between the
number type primitive values and number objects and between the string type primitive values and string
objects. The methods of Number and String objects can be used on variables of the corresponding primitive
types.
Suppose that prim is a primitive variable with the value 17 and obj is a Number object with property value 17.
prim and obj are stored differently .
Numeric literals – like Java All numeric values are stored in double-precision floating point. Numeric values
in Javascript are often called numbers. Numeric literals can be either integer or floating point values.
String literals are delimited by either ' or " .Can include escape sequences (e.g., \n,\t).
Var str1=”Hello”;
Var str2=’Hello’;
To include a single quote character in a string delimited by single quotes, the embedded single quote must be
preceded by a backslash.
A double quote can be embedded in a double quoted string literal by preceding it with a backslash.
Boolean values are true and [Link] for evaluating Boolean Expressions.
Var boo2=false;
The only value of type Null is reserved word null which means no value. A variable is Null if it has not been
explicitly declared or assigned a value.
The only value of type Undefined is undefined. If a variable has been explicitly declared, but not assigned a
value it has the value undefined.
[Link](carName);
[Link] variables
JavaScript is dynamically typed – any variable can be used for anything ie variable are not typed but values are
typed. A variable can have values of any primitive type, or it can be a reference to any objects .The interpreter
determines the type of the value of a particular occurrence of a variable. Variables can be implicitly or
explicitly declared.
• A variable can be declared either by assigning it a value(implicit)in which case the interpreter
implicitly declares it to be a variable or by listing it in a declaration statement that begins with the
reserved word var(explicit)
3. Uses of JAVASCRIPT
• Provide programming capability at both the server and the client ends of a Web connection.
• Perform calculations
• Validation of input
• Less server interaction – we can validate the user i/p before sending the page off to the server. This
saves server traffic.
• When a JavaScript code is encountered in the HTML document, the browser uses its JavaScript
interpreter to “execute” the script. Output from the script becomes the next markup to be rendered.
When the end of the script is reached, the browser goes back to reading the HTML document and
displaying its content.
• In explicit embedding, the JavaScript code physically resides in the HTML document.
• In implicit embedding the JavaScript can be placed in its own file, separate from the HTML document.
• When JavaScript scripts are explicitly embedded, they can appear in either part of an
HTML document—the head or the body
• The interpreter notes the existence of scripts that appear in the head of a document, but it does not
interpret them while processing the head. This method is useful when using Javascript functions.
The function can be defined in the head of the HTML [Link] that are found in the body of
a document are interpreted as they are found.
[Link] Operators
5.1Arithmetic Operators
• Eg:increment operator If
(a++)*3 = 21
In both cases a is set to 8
The precedence rules of a language specify which operator is evaluated first when two operators with different
precedence are adjacent in an expression.
The associativity rules of a language specify which operator is evaluated first when two operators with the same
precedence are adjacent in an expression.
• Operator Associativity
*,/,% Left
>,<,>=,<= Left
==,!= Left
===,!=== Left
&& Left
|| Left
=,+=,-=,*=,/=,&&=,||=,%= Right
var a=2,
b=4,c,d; C=3+a*b;
11 d=b/a/2;
precedence. (a+b)*c
5.2Assignment Operators
[Link] Operators
function greet(name) {
In this example:
When you call the function greet('Alice'), it returns the string 'Hello, Alice!', which is then stored in the
variable message and logged to the console.
Functions can take multiple parameters, have default values, and be used in various ways, such as being
assigned to variables, passed as arguments to other functions, or even returned from other functions. They
are a fundamental part of JavaScript and are used for code modularity and reusability.
The Window object has three methods for creating dialog boxes for user interactions , alert, confirm
, and prompt
The alert method opens a dialog window and displays its parameter in that window. It also displays an
OK
button
O/P
The confirm method opens a dialog window in which the method displays its string parameter along with
two buttons OK and Cancel to offer the user the choice of continuing some process.
Var question = confirm(“Do you want to continue this download”);
O/P
The prompt method used to create dialog window that contains a textbox used to collect string of input
from from the user .The window also includes 2 buttons: OK and [Link] prompt takes 2
parameters: the string that prompts user for input and a default string in case user does not type a
string before pressing one of the 2 buttons.
O/p
1. alert
Parameter in alert is plain text, not [Link] a dialog box which displays the parameter
string and an OK button.
<!DOCTYPE html>
OUTPUT
2. confirm
Opens a dialog box and displays the parameter and two buttons, OK and Cancel
if (confirm("Press a button!"))
{
txt = "Do you want to continue?";
} else {
txt = "You pressed Cancel!";
} [Link](txt);
3. Prompt
Opens a dialog box and displays its string parameter, along with a text box and two buttons, OK and
Cancel.
The second parameter is for a default response if the user presses OK without typing a response in the
text box (waits for OK) .
[Link](txt);
} else {
[Link](res);
</script>
CONTROL STATEMENTS
Conditional Statements
• if statement - use this statement if you want to execute some code only if a specified condition is true
• if...else statement - use this statement if you want to execute some code if the condition is true
and another code if the condition is false.
• if...else if else statement - use this statement if you want to select one of many blocks of code to be
executed .
• switch statement - use this statement if you want to select one of many blocks of code to be executed .
Control
Statements-1 if
(condition)
<script>
""); if(x=="admin")
</script>
if-else
if (condition)
else
Example
if(x<0)
alert ("negative");
else
alert ("positive");
}
</script>
else if Statement
Use the else if statement to specify a new condition if the first condition is false.
Syntax
if (condition1)
{
block of code to be executed if condition1 is true
} else if (condition2)
{
block of code to be executed if the condition1 is false and condition2 is true
} else {
block of code to be executed if the condition1 is false and condition2 is false
}
Example
<script>
} else
alert(greeting);
</script>
• Use the switch statement to select one of many blocks of code to be executed.
Syntax
switch(expression)
{
case n:
code block
break;
case n:
code block
break;
default:
code block
}
<script type=”text/javascript”>
switch (day) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day =
"Tuesday";
break;
case 3:
day =
"Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
alert(day);
</script>
Loop Statements
Different Kinds of Loops
do/while - also loops through a block of code while a specified condition is true
for loop
syntax:
{
code block to be executed
}
• Statement 2 defines the condition for running the loop (the code block).
• Statement 3 is executed each time after the loop (the code block) has been executed.
Example
for (i = 0; i < 5; i++)
{
text += "The number is " + i + "<br>";
alert(text);
}
for/in Loop
• Example
{
text += person[x];
alert(text);}
While Loop
• The while loop loops through a block of code as long as a specified condition is true.
while (condition)
{
code block to be executed
}
Example
var i=0;
alert("i="+i);
i++;
</script>
Do/While Loop
• The do/while loop is a variant of the while loop.
• This loop will execute the code block once, before checking if the condition is true, then it will
repeat the loop as long as the condition is true.
Syntax
do {
code block to be executed
}
while (condition);
Example
<script type=”text/javascript”>
var i=0;
do
alert("i="+i);
i++;
</script>
Break
The break statement "jumps out" of a loop. It was used to "jump out" of a switch() statement. break statement
also be used to jump out of a loop. The break statement breaks the loop and continues executing the code after
the loop (if any):
Example
<script type="text/javascript">
var i,text="";
if (i === 3) { break; }
alert(text);
}
</script>
Continue Statement
• The continue statement breaks one iteration (in the loop), if a specified condition occurs, and
continues with the next iteration in the loop.
<script type="text/javascript">
var i, text="";
if (i === 3) { continue; }
}alert(text);
</script>
OBJECTS CREATION
JavaScript Objects (characteristics)
Example
The object (person) in the example above has 4 properties: firstName, lastName, age, and eyeColor.
A JavaScript object is a collection of named values . The named values, in JavaScript objects, are
called properties.
3)Define an object constructor, and then create objects of the constructed type.
Easiest way to create a JavaScript Object. Using an object literal, define and create an object in one statement.
The following example creates a new JavaScript object with four properties:
var person = {
firstName:“xyz",
lastName:“pqr",
age:50,
eyeColor:"blue"
};
The following example also creates a new JavaScript object with four properties:
Example
3)Define an object constructor, and then create objects of the constructed type
Because the objects can be nested , we can create new objects with the properties of person with the properties
of its own.
[Link]=“Ernakulam”;
[Link]=“Kerala”;
Example:
[Link] = first;
[Link] = last;
[Link] = age;
[Link] = eyeColor;
[Link]([Link]); // Output: 50
Properties are the values associated with a JavaScript object.A JavaScript object is a collection of unordered
[Link] can usually be changed, added, and deleted, but some are read only.
or
objectName["property"] // person["age"]
or
objectName[expression] // x = "age";
old.";
or
The JavaScript for...in statement loops through the properties of an object. The block of code inside of the
for...in loop will be executed once for each property.
Syntax
{
code to be executed
}
Example
{
txt += person[x];
}
You can add new properties to an existing object by simply giving it a value. Assume that the person object
already exists - you can then give it new properties:
Example
[Link] = “kochi";
• Example
The delete keyword deletes both the value of the property and the property itself. After deletion, the property
cannot be used before it is added back again. The delete operator is designed to be used on object properties. It
has no effect on variables or functions.
Adding a Method to an Object
[Link] =fname;
[Link] = lname;
[Link] = age;
[Link] = function ()
{
return [Link] + " " + [Link];
};
When a JavaScript variable is declared with the keyword "new", the variable is created as an object:
// Declares x as a String
object var y = new Number();
// Declares y as a Number
object var z = new Boolean();
JavaScript Arrays
• JavaScript arrays are used to store multiple values in a single variable.
• Example
Creating an Array
Array. Syntax:
The following example also creates an Array, and assigns values to it:
Example
EXAMPLE
<!DOCTYPE html>
<html>
<body>
<h1 id="demo"></h1>
<script>
[Link]("demo").innerHTML = s[0]+
</script>
</body>
</html>
alert([Link]); //return 3
Example
[Link](“XX");
Example
<!DOCTYPE html>
<html><body><h1 id="demo"></h1>
<script>
[Link]("XX");
[Link]("demo").innerHTML +=
</script>
</body></html>
• New element can also be added to an array using the length property:
var s = ["BB", "OO", "AA", "MM"];
s[[Link]] = "LL";
• Adding elements with high indexes can create undefined "holes" in an array:
s[6] = "PP";
Popping
• Example
• The pop() method returns the value that was "popped out":
• Example
Shifting Elements
• Shifting is equivalent to popping, working on the first element instead of the last.
• The shift() method removes the first array element and "shifts" all other elements to a lower index.
• Example
unshift() method
• The unshift() method adds a new element to an array (at the beginning), and "shifts" older elements:
Example
Example
var s = ["BB", "OO", "AA", “MM"]; alert([Link](“AA"); //
Returns 5
Deleting Elements
Since JavaScript arrays are objects, elements can be deleted by using the JavaScript operator delete:
Example
var s = ["BB", "OO", "AA", “MM"]; delete s[0]; // Changes the first element in s to
undefined Using delete may leave undefined holes in the array. Use pop() or shift() instead.
slice() method
Eg: slices out a part of an array starting from array element 1 ("Orange"):
• slice() method creates a new array. It does not remove any elements from the source [Link] returns the
part of the array object specified by its parameters.
• This example slices out a part of an array starting from array element 3 ("Apple"):
• The slice() method can take two arguments like slice(1, 3).
• The method then selects elements from the start argument, and up to (but not including) the
end argument.
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = [Link](1, 3);
Sorting an Array
By default, the sort() function sorts values as strings. This works well for strings . However, if numbers are
sorted as strings, "25" is bigger than "100", because "2" is bigger than "1". Because of this, the sort() method
will produce incorrect result when sorting numbers. Use compare function for numeric sorting .
Reversing an Array
The reverse() method reverses the elements in an array. use it to sort an array in descending order:
Associative Arrays
Arrays with named indexes are called associative arrays (or hashes). JavaScript does not support arrays with
named indexes. In JavaScript, arrays always use numbered indexes.
function function_name(param0) {
–statements–
}
function function_name(param0, param1) {
–statements–
}
function function_name(param0, param1, /* …, */ paramN) {
–statements–
}
Creating a session Variable.
<?php
// Start the session
session_start();
require: In contrast, the require statement will produce a fatal error (E_COMPILE_ERROR) and stop the
script if the file cannot be found. This is typically used when the file is critical for the application, and you
do not want the script to continue without it.
● Use include when the file is not mandatory, and the application should still run if the file is
missing.
● Use require when the file is essential, and the application should not continue if the file is not
found.
mysqli_query(): This function is used to perform a query against the database. It returns FALSE on failure
and for successful SELECT, SHOW, DESCRIBE, or EXPLAIN queries it will return a mysqli_result object.
For other successful queries, it will return TRUE
mysqli_num_rows(): This function returns the number of rows in a result set. It’s useful for determining
the number of rows returned by a SELECT query
mysqli_fetch_array(): This function fetches a result row as an associative array, a numeric array, or both.
It’s used to read a single row from a result set