Web Explore Javascript Saugata
Web Explore Javascript Saugata
EXPLORE WEB
Saugata Sarkar
Explore Web using HTML, CSS and JavaScript
TABLE OF CONTENTS
Sl Chapters Page
CHAPTER 1
HTML – Web Introductions,
Basic Formatting Tags
Web architecture consists of several components, including the client, the server, the network,
and the database. The client is the web browser or application that the user interacts with, and
the server is the computer or group of computers that host the website or web application. The
network is the infrastructure that connects the client and the server, such as the internet. The
database is a collection of data that is used to store and retrieve information for the website or
web application.
Web architecture also includes the design and layout of the website or web application, as well
as the way it is organized and the relationships between different pages and components.
The client −This is the web browser or application that the user interacts with. The client sends
requests to the server and receives responses from the server.
The server −This is the computer or group of computers that host the website or web
application. The server processes requests from the client and sends back the appropriate
response.
The network This is the infrastructure that connects the client and the server, such as the
internet. It allows for communication between the client and the server.
The database −This is a collection of data that is used to store and retrieve information for the
website or web application. The database can be located on the same server as the website or
web application, or it can be hosted on a separate server.
The design and layout −This refers to the way the website or web application is structured and
organized, including the layout, navigation, and overall appearance.
The frameworks and libraries − These are tools and resources that are used to build and
maintain the website or web application. They can include frameworks like Ruby on Rails or
Django, or libraries like jQuery or React.
The deployment and hosting − This refers to the way the website or web application is
deployed and hosted, including the hosting environment (such as a shared hosting plan or a
cloud platform) and the process for deploying updates and changes to the website or web
application.
Conclusion -
Web servers are the backbone of the internet, enabling us to access and interact with websites
and web applications every day. Understanding their working and architecture is essential for
web developers, administrators, and anyone interested in the digital world. Whether you’re
running a personal blog or managing a complex e-commerce platform, web servers play a pivotal
role in delivering online content efficiently and securely.
What is HTML?
HTML is an acronym which stands for Hyper Text Markup Language which is used for creating
web pages and web applications. Let's see what is meant by Hypertext Markup Language, and
Web page.
Hyper Text: HyperText simply means "Text within Text." A text has a link within it, is a
hypertext. Whenever you click on a link which brings you to a new webpage, you have clicked
on a hypertext. HyperText is a way to link two or more web pages (HTML documents) with each
other.
Markup language: A markup language is a computer language that is used to apply layout and
formatting conventions to a text document. Markup language makes text more interactive and
dynamic. It can turn text into images, tables, links, etc.
Web Page: A web page is a document which is commonly written in HTML and translated by a
web browser. A web page can be identified by entering an URL. A Web page can be of the static
or dynamic type. With the help of HTML only, we can create static web pages.
HTML Tags
HTML tags are like keywords which defines that how web browser will format and display the
content. With the help of tags, a web browser can distinguish between an HTML content and a
simple content.
An HTML file must have some essential tags so that web browser can differentiate between a
simple text and HTML text. You can use as many tags you want as per your code requirement.
1. Container Tag
Container tag : These tags are in which we define the text or other tag elements.
These actually consist two tags, a start tag and an end tag, which enclose the text.
<html>
<head> </head>
<body>
</body>
</html>
2. Empty(Non-Container/Blank) tag
Non- container tag/empty tag : These are standalone text do not contain text. Or any other tag element.
<br/>
<hr/>
<input type="text"/>
Example 1
<html>
<head>
<title>Web page title</title>
</head>
<body>
<h1>Write Your First Heading</h1>
<p>Write Your First Paragraph.</p>
</body>
</html>
HTML Comments
HTML comments are not displayed in the browser, but they can help document your HTML source code.
You can add comments to your HTML source by using the following syntax:
Notice that there is an exclamation World (!) in the start tag, but not in the end tag.
Add Comments
With comments you can place notifications and reminders in your HTML code:
Example
<html>
<body>
<!-- This is a comment -->
<p>This is a paragraph. </p>
<!-- Comments are not displayed in the browser -->
</body>
</html>
Heading Tags
Heading tags are used to define headings of documents. You can use different sizes for your
headings. HTML also has six levels of headings, which use the
elements <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>.
Example 2
<html>
<head>
<title>Heading Example</title></head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body></html>
Paragraph Tag
The <p> tag offers a way to structure your text into different paragraphs. Each paragraph of
text should go in between an opening <p> and a closing </p> tag.
Example 3
<html>
<head>
<title>Paragraph Example</title>
</head>
<body>
<p>Here is a first paragraph of text.</p>
<p>Here is a second paragraph of text.</p>
</body>
</html>
The <br /> tag has a space between the characters br and the forward slash /. If you omit this
space, older browsers will have trouble rendering the line break, while if you miss the forward
slash character and just use <br>, it is not valid in XHTML.
Example 4
<html>
<head>
<title>Line Break Example</title>
</head>
<body>
<p>Hello<br /> You delivered your assignment on time.<br />
Thanks<br />Mahnaz</p>
</body>
</html>
Center Tag
The <center> tag aligns text, images, or other HTML elements in the middle of a web page.
Note: The <center> tag is deprecated in HTML5. You can use the CSS text-align property to center
elements.
Example
<html>
<head>
<title>Cantering Content Example</title>
</head>
<body>
<p>This text is not in the center.</p>
<center>
<p>This text is in the center.</p>
</center>
</body>
</html>
Example
<html>
<head>
<title>Horizontal Line Example</title>
</head>
<body>
<p>This is paragraph one and should be on top</p>
<hr />
<p>This is paragraph two and should be at bottom</p>
</body>
</html>
The <hr /> tag is an example of the empty element, where you do not need opening and closing
tags, as there is nothing to go in between them.
Listing Tags
The <ul> and <ol> tags create the unordered and ordered listings, and to display list items, the <li> tag is
used.
Example
<html>
<head>
<title>Listing Tags Example</title>
</head>
<body>
<h2>Unordered list</h2>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<h2>Ordered list</h2>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</body>
</html>
HTML Elements
HTML elements are the basic building blocks to create a web page; they are created with the
help of an opening tag, content, and ending tag. HTML documents consist of a tree of these
elements, and they specify how HTML documents should be built, and what kind of content
should be placed within various parts of an HTML document.
An HTML document consists of a tree of HTML elements, and they define the content and layout of a
webpage, like how and what content should display in the different sections of a webpage.
Example
The following table displays the different parts (opening tag, content, and closing tag) of the
HTML elements used in the above example:
The following image demonstrates the structure of an element, like how an HTML element is
written with the opening and closing tags:
For example, <p> is the starting tag of a paragraph, and </p> is the closing tag of the same
paragraph, but <p>This is paragraph</p> is a paragraph element.
Example
In the following example, we are nesting the italicized element (<i>...</i>) within
the h1 element and underline (<u>...</u>) element within the paragraph element.
<html>
<head>
<title>Nested Elements Example</title>
</head>
<body>
<h1>This is <i>italic</i> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
</body>
</html>
Some of the void elements are such as <img />, <hr />, and <br /> elements. The below table
shows a list of void elements −
Example
<html>
<body>
<p>This line contains a line break tag, <br> hence content is visible in two separate lines.</p>
<p>This line is <hr>separated by a horizontal rule.</p>
</body>
</html>
Therearedifferenttagsforvariousformattingtags.EachTaghasitsowntypeofformattingassociatedwithit.
The HTML <b> Tag defines bold text. Bold text is wider and darker text than the default text,
without any extra importance to the browser. Look at the example below.
<html>
<head>
<title> Bold Text </title>
</head>
<body>
<p>This is Normal Text. </p>
<b>This is Bold Text. </b>
</body>
</html>
The HTML <strong> Tag displays same formatting like a <b> tag. But the Strong text has some
importance to the browser and search engines. It is always recommended to write keywords
within <strong> Tag to give them extra importance.
<html>
<head>
</head>
<body>
</body>
</html>
The HTML <i> Tag defines italic text. This type of formatting displays cursive font based text
that slant slightly to the right.
<html>
<head>
<title> Italic Text </title>
</head>
<body>
<p>This is normal text </p>
<i>This text in Italic </i>
</body>
</html>
The HTML <u> Tag defines Underlined text. All the text within the <u> and </u> tags will have an
underline throughout.
Underlined Text is used to draw attention of the user and is a default formatting for a hyperlinked text.
<html>
</head>
<body>
</body>
</html>
The HTML <sub> element defines subscripted text. This type of text is small in size and is placed slightly
below the normal line of text.
<html>
<head>
<title> Subscript Text </title>
</head>
<body>
<p> This is Subscripted Text </p>
<p> H<sub>2 </sub> O
</body>
</html>
<html>
<head>
<title> Superscript Text </title>
</head>
<body>
<p> This is Superscripted Text </p>
<p> (a+b)<sup>2</sup>
</body>
</html>
Font tag
The <font> tag was used in earlier versions of HTML to define the size, color, and face of the text.
However, it has been deprecated in HTML5, and it's better to use CSS for styling text. But for learning
purposes, here’s how the <font> tag worked.
<!DOCTYPE html>
<html>
<head>
<title>Font Tag Example</title>
</head>
<body>
<p>This is a normal paragraph.</p>
<p><font color="red" size="4" face="Arial">This is a red Arial text with size 4.</font></p>
<p><font color="blue" size="6" face="tahoma"> family is Tahoma </font></p>
</body>
</html>
Lab Assignment
HTML Assignment 1
2. Create the below web page using <b> <i> <u> <strong> <p> tags
3. Create a page with <p> tags and its alignment with <sup> and <sub> tags
Objective: Use the <font> tag to apply different styles like color, size, and face to a paragraph.
Task:
CHAPTER 2
HTML – List and Table
HTML Lists
Our day-to-day lives often involve the use of lists. For example, when we go shopping, the bill
we receive includes a list of all the items we've purchased. In a similar manner, web developers
use lists to neatly display data on websites.
HTML provides different types of lists to display data in various forms. Each list contains one or
more list items.
Ordered List: Displays items in a numerical sequence, and supports various numbering styles
like Arabic numerals, Roman numerals, and so on.
Definition List: Organizes items in a format similar to a dictionary, with terms and their
corresponding definitions.
An Unordered List
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items will be marked with bullets (small black circles) by default:
Example
<html>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
An Ordered List
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:
Example
<html>
<body>
<ol>
<li>Hardware</li>
<li>Software</li>
<li>Tally</li>
</ol>
</body>
</html>
A Description List
Example
<html>
<body>
<h2>A Description List</h2>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
</body>
</html>
Tables are also used in websites to present any data to the user. It looks really neat and also
everyone prefers tabular form of data nowadays. The HTML tables allows to arrange data like
text, images, etc. into rows and columns.
Example
<html>
<HTML>
<head> <title> HTML Table </title> </head>
<body>
<table>
<tr>
<th> Name </th>
<th> Salary </th>
<th> Age </th>
</tr>
<tr>
<td>Anshuman</td>
<td>Rs. 2,00,000 </td>
<td> 25 </td>
</tr>
<tr><td>Kuldeep</td>
<td>Rs. 5,00,000 </td>
<td> 22 </td>
</tr>
</table>
</body>
</html>
Table Row
A table row can be defined with the <tr> tag It is also a paired tag with </tr> as a closing tag.
Whatever written between these tags will be displayed in a single row of the table. To create a
new row another <tr> tag is written after closing the previous one.
Table heading
A table header in HTML tables is a special case of a table row. It starts with <th> tag and ends
with </th> tag. There only difference between a row and a heading is that text written inside
<th> tags is displayed in bold fonts and is by default centered aligned by the browser. Because
of its properties this tag is used only for writing Heading of the table. You can also make a <tr>
tags content bold and centered by using CSS It will work exactly like <th> tag.
Table Cells
A table cell in an HTML table is defined by <td> tag. It is also a paired tag with </td> as a closing
tag. Each pair of these tags represents a cell in a row. It is used inside &glt;tr> tags only.
Without <tr> tags it is of no value. After declaring the rows the <td> tags are used to enter data
in the table. Whatever is written inside the <td> and </td> tags will be displayed by the browser
in the tables as it is.
Table Attributes
The <table> Tag in HTML table has many attributes which can be used to further define the
structure of the table than just a standard one. These attributes can make a table look a bit
more attractive. Let’s see one by one the different attributes of the table tag and then we will
use them in an example and will see the changes in the table.
Example
<html>
<head>
<title> HTML Table Border Attribute </title>
</head>
<body>
<table border="1" width="30%">
<tr>
<th> Product </th>
<th> Price </th>
</tr>
<tr>
<td>Bag </td>
<td> Rs. 2500 </td>
</tr>
<tr>
<td>Jacket</td>
<td>Rs. 5000 </td>
</tr>
</table>
</body>
</html>
Cellpadding attribute
The Cellpadding attribute is used to specify the space between the content of the cell and its borders. It
provides padding to the content of the cell. As its value increases the space between the cell’s content
and its border is also increases. The value of this attribute is taken in pixels by the browser. The
cellpadding is applied to all the four sides of the content. The value can also be defined in percentages.
Cellspacing attribute
The Cellspacing attribute is used to specify the space between the cells of the table. Its value can be in
pixels or in percentages. It works similar to the Cellpadding attribute but only between cells. It is applied
to all the sides of the cells.
Example
<html>
<head>
<title> HTML Table Cellpadding Attribute </title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="5" style="width:30%">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Peter</td>
<td>5000</td>
</tr>
<tr>
<td>John</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
HTML tables can have cells that span over multiple rows and/or columns.
NAME 2022
APRIL
FIESTA
The 'Rowspan'
The rowspan attribute is used to merge two or more rows together to form a single row. A single row
occupies space of the number of merged rows.
<html>
<head> </head>
<body>
<h2>Cell that spans two rows</h2>
<table style="width:50%" border='1'>
<tr>
<th>Name</th>
<td>Jill</td>
</tr>
<tr>
<th rowspan="2">Phone</th>
<td>555-1234</td>
</tr>
<tr>
<td>555-8745</td>
</tr>
</table>
</body>
</html>
The 'Colspan'
The colspan attribute is used to merge two or more columns into a single column. single column
occupies space of the number of merged columns.
<html>
<head>
</head>
<body>
<h2>Cell that spans two columns</h2>
<p>To make a cell span more than one column, use the colspan attribute.</p>
<table style="width:50%" border='1'>
<tr>
<th colspan="2">Name</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>43</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>57</td>
</tr>
</table>
</body>
</html>
Lab Assignment
1. Create the below webpage with basic HTML List tags
List of Courses
Programming Courses
1. PYTHON
2. Java
3. C Programming
a. HTML
b. CSS
c. Bootstrap
1. Fruit
1. Apples
2. Oranges
3. Pears
4. Mango
2. Vegetables
1. Broccoli
2. Peas
3. Capsicum
1. Green Capsicum
2. Yellow Capsicum
3. Red Capsicum
4. Corn
Basic Course
Sr. Course Name Fees Duration Eligibility
No
1 CCC - Course on Computer Concept ₹ 4000 3 10th
Months
2 CCA - Course on Computer ₹ 3000 3 10th
Application Months
3 Tally ₹ 4000 3 10th
Months
4 O Level ₹ 1 Year 12th
20,000
4. Create the below table with basic HTML Table tags
CHAPTER 3
HTML – Building Forms and Hyperlinks
HTML Forms
An HTML form is used to collect user input. The user input is most often sent
to a server for processing.
The HTML <form> element is used to create an HTML form for user input:
<form>
form elements
</form>
The <form> element is a container for different types of input elements, such as: text fields, checkboxes,
radio buttons, submit buttons, etc.
An <input> element can be displayed in many ways, depending on the type attribute.
Type Description
<input type="radio"> Displays a radio button (for selecting one of many choices)
<input type="checkbox"> Displays a checkbox (for selecting zero or more of many choices)
HTML forms are used to collect user inputs, and several form elements are available to facilitate
this. Here is an overview of important form elements:
Example:
4. Select (<select>)
<select name="country">
<option value="india">India</option>
<option value="usa">USA</option>
<option value="uk">UK</option>
</select>
5. Textarea (<textarea>)
Text Fields
The <input type="text"> defines a single-line input field for text input.
Example
<html>
<body>
<h2>Text input fields</h2>
<form>
Enter name
<input type="text" name="fna" value="">
<br> <br>
Enter age
<input type="text" name="age" size="4">
</body>
</html>
The <label> element is useful for screen-reader users, because the screen-reader will read out loud the
label when the user focuses on the input element.
Radio Buttons
The <input type="radio"> defines a radio button. Radio buttons let a user select ONE of a limited
number of choices.
Example
<html>
<body>
<h2>Radio button</h2>
<form>
Enter Gender
<input type="radio" name="gender" value="">Male
<input type="radio" name="gender" value="">Female
</body>
</html>
Checkboxes
The <input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE options
of a limited number of choices.
<html>
<body>
<h2>Checkbox </h2>
<form>
Soft Drink you prefer <br> <br>
<input type="checkbox" name="c2" value="">Coke
<input type="checkbox" name="c2" value="">Limca
<input type="checkbox" name="c3" value=""> Fanta
</body>
</html>
</body>
</html>
Select
<html>
<head>
<title>Country Selection</title>
</head>
<body>
<form>
<h2>Select your country:</h2>
<select name="country">
<option value="india">India</option>
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="uk">UK</option>
</select><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Anchor Tag
Links are fundamental to navigating the web. In HTML, links are created using the <a> tag, also known as
the Anchor tag.
<html lang="en">
<head>
<title>Linking to Sections on Same Page</title>
</head>
<body>
<h1>Care Container Lines - Shipping Services</h1>
Link Colors
Links typically appear in different colors based on their state:
Active: Displayed in red and underlined like this sentence
Visited: Appears purple and underlined like this sentence
Unvisited: Shown as blue and underlined like this sentence
Objective: Create a basic form for booking cargo shipment with details about
sender, receiver, and shipment.
Task:
CHAPTER 4
CSS – Introduction,
Different Types of CSS
What is CSS?
CSS stands for Cascading Style Sheets, it is a simple design language intended to simplify the
process of making web pages presentable using CSS properties. CSS specify how an HTML
element should be displayed on the web page. If you think of the human body as a web page
then CSS is styling part of the body. Like color of the eyes, size of the nose, skin tone, etc.
Types of CSS
There is no types in CSS, it actually refer - "In how many ways we can use CSS?" So there are
three ways to use CSS on HTML document.
Inline CSS: Inline CSS are directly applied on the HTML elements and it is the most
prioritize CSS among these three. This will override any external or internal CSS.
Internal CSS: Internal CSS are defined in the HTML head section inside of <style> tag to
let the browser know where to look for the CSS.
External CSS: External CSS are defined in a separate file that contains only CSS
properties, this is the recommended way to use CSS when you are working on projects.
It is easy to maintain and multiple CSS files can be created and you can use them by
importing it into your HTML document using HTML <link> tag.
CSS Example
Here in this example we will show you above mentioned ways to use CSS on an HTML document.
<html>
<head>
<title>CSS Tutorial</title>
<!-- Internal CSS -->
<style>
span{
color: green;
}
</style>
<body>
<h1><span>Tutorial</span>World</h1>
</html>
External CSS File: We are importing this file into the above codethrough <link> tag. And the file
name is style.css. Above code will follow the style of this file on the portal you have to create
files locally and try it on your system.
body {
margin-left: 40%;
margin-top: 40%;
}
CSS Syntax
One has to check the three components i.e, selector, property and value.
Selector: CSS selectors are used to select the element or groups of elements to style on a web page.
Property: A CSS property is an aspect or characteristic of an HTML element that can be styled or
modified using CSS, such as color, font-size, or margin.
Value: Values are assigned to properties. For example, color property can have value like red, green etc.
For Example:
Syntax
selector{
property1: value1;
property2: value2;
property3: value3;
}
Example
<html>
<head>
<style>
p{
background-color: black; color: white; padding: 5px;
}
.special {
color: lightblue; /* Change text color */
}
</style>
</head>
<body>
<p> This a normal paragraph... </p>
<br>
<p class="special"> This is a paragraph with class special... </p>
<br>
</body>
</html>
Instructions:
Objective: Learn how to set background colors and background images in CSS.
Instructions:
Instructions:
Instructions:
1. Create an HTML file with a table displaying a list of shipping services offered by "Care Container
Lines."
2. Style the table using CSS to add borders, background colors, and align text within the table cells.
3. Apply different styles to the table headers and table rows.
(The HTML page is created here for your reference namely Lab4.htm
<html>
<head>
<title>How to Book a Service</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>How to Book a Shipping Service</h1>
<ol>
<li>Visit our website and sign in.</li>
<li>Choose the shipping service you require.</li>
<li>Enter the shipping details, including destination and package size.</li>
<li>Review and confirm your booking.</li>
<li>Make the payment to complete the booking process.</li>
</ol>
</body>
</html>
style.css
CHAPTER 5
CSS – Selectors and Box Model
CSS - Selectors
CSS Selectors are used to select the HTML elements you want to style on a web page. They
allow you to target specific elements or groups of elements to apply styles like colors, fonts,
margins, and more.
The element or elements that are selected by the selector are referred to as subject of the
selector.
Types of Selectors
1. Universal Selectors
2. Element Selectors
3. Class Selectors
4. Id Selectors
5. Attribute Selectors
6. Group Selectors
7. Pseudo-element Selectors
8. Pseudo-class Selectors
Syntax
*{
margin: 0;
padding: 0;
}
As per the above syntax, the universal selector is used to apply a margin and padding of 0 to all
HTML elements.
Example
<html>
<head>
<style>
*{
margin: 0;
padding: 0;
background-color: peachpuff;
color: darkgreen;
font-size: 25px;
}
</style>
</head>
<body>
<h1>Universal selector (*)</h1>
<div>
Parent element
<p>Child paragraph 1</p>
<p>Child paragraph 2</p>
</div>
<p>Paragraph 3</p>
</body>
</html>
Syntax
Example
<html>
<head>
<style>
div {
border: 5px inset gold;
width: 300px;
text-align: center;
}
p{
color: green;
}
h1 {
text-decoration-line: underline;
}
</style>
</head>
<body>
<div>
<h1>Element selector</h1>
<p>Div with border </p>
<p>Text aligned to center</p>
<p>Paragraph with green color</p>
<p>h1 with an underline</p>
</div>
</body>
</html>
Syntax
.sideDiv {
text-decoration-line: underline;
}
.topDiv {
color: green;
font-size: 25px;
}
Example
<html>
<head>
<style>
.class1{
border: 5px solid black; height:80px; width: 180px; text-align: center;
padding:70px;
font-size:40px;
}
</style>
</head>
<body>
<div class="class1">
This is box
</div>
</body>
</html>
CSS ID Selector
An ID selector targets single element with a particular value for id attribute to style it. An id in CSS is
denoted by "#" (hash) symbol. Same class can be applied to multiple elements, but an id is unique for an
element.
Syntax
#style-p {
color: green;
font-size: 25px;
}
#style-h1 {
text-decoration-line: underline;
color: red;
}
Example
<html>
<head>
<style>
#style-div {
border: 5px solid red;
width: 300px;
text-align: center;
height : 200px;
background-color:green;
}
</style>
</head>
<body>
<div id="style-div">
This is box
</div>
</body>
</html>
Syntax
Example
<html>
<head>
<style>
/* This applies to both <h1> and <h2> elements */
h1, h2 {
background-color: grey;
padding: 4px;
}
</style>
</head>
<body>
<h1>CSS Selectors</h1>
<h2>Group Selectors</h2>
</body>
</html>
Syntax
Example
<html>
<head>
<style>
a:hover {
background-color: peachpuff; color: green; font-size: 2em;
}
button:active {
background-color: yellow;
}
</style>
</head>
<body>
<h2>Pseudo-class selector</h2>
<p> Styling applied to anchor element and button with a pseudo-class: </p>
<a href="https://www.onwardacademy.in"> Onward Academy </a>
<br><br> <button>Click Me</button>
</body>
</html>
Syntax
Example
<html>
<head>
<style>
/* Add and style contents before paragraph */
p::before {
content: "Note: ";
font-weight: bold;
color: red;
}
The CSS box model is essentially a box that wraps around every HTML element. It consists of:
content, padding, borders and margins. The image below illustrates the box model:
Content - The content of the box, where text and images appear
Padding - Clears an area around the content. The padding is transparent
Border - A border that goes around the padding and content
Margin - Clears an area outside the border. The margin is transparent
The box model allows us to add a border around elements, and to define space between
elements.
Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
</style>
</head>
<body>
<h2>Demonstrating the Box Model</h2>
<div></div>
</body>
</html>
Objective: Learn how to style different heading tags (h1 to h6) using CSS.
Instructions:
1. Create an HTML page with a title and at least six headings (h1 to h6).
2. Use CSS to style each heading with different font sizes, colors, and text alignments.
3. Add different background colors or borders for each heading.
html >
style2.css
<head>
<title>Styling Headings</title>
<link rel="stylesheet" href="style2.css"> h1 {
</head> color: darkblue;
<body> font-size: 40px;
<h1>Main Heading (h1)</h1>
text-align: center;
<h2>Subheading (h2)</h2>
<h3>Subheading Level 3 (h3)</h3> background-color: lightgray;
Objective: Learn how to style unordered lists using different bullet types and text styles.
Instructions:
1. Create an HTML page with an unordered list of items (e.g., services provided by "Care Container
Lines").
2. Use CSS to change the bullet style of the unordered list (ul).
3. Experiment with different list styles like circle, square, and none. Also, apply custom styles
like padding, margins, and background colors.
Objective: Learn how to style unordered lists (ul) and list items (li) using CSS.
Instructions:
1. Create an unordered list with five items, describing services offered by "Care Container Lines."
2. Use CSS to change the bullet style, list item text color, and spacing.
3. Add hover effects for the list items (e.g., changing the color when hovered).
<html>
// style3.css
<head>
ul {
<title>Unordered List Example</title>
list-style-type: square;
<link rel="stylesheet" href="style3.css">
padding-left: 20px;
</head>
}
<body>
<h2>Our Services</h2>
<ul> li {
font-size: 18px;
<li>Cargo Shipping</li>
color: darkblue;
<li>Container Tracking</li>
margin-bottom: 10px;
<li>Customs Clearance</li>
}
<li>Warehousing</li>
<li>Freight Forwarding</li>
li:hover {
</ul>
color: green;
font-weight: bold;
</body>
</html> }
Objective: Learn how to style images using CSS, including width, height, borders, and
alignment.
Instructions:
1. Create an HTML file with an image of a cargo ship (use a placeholder image if necessary).
2. Style the image using CSS to control its size, add borders, and align it to the center of the page.
3. Apply hover effects to the image (e.g., increasing its size on hover).
<!DOCTYPE html>
<html lang="en">
// style4.css
<head>
.cargo-image {
<title>Image Styling Example</title>
<link rel="stylesheet" href="image-styles.css"> width: 60%;
</head> display: block;
<body> margin: 20px auto;
<h1> Simple stylesheet with Image </h1> border: 5px solid darkblue;
border-radius: 10px;
<h2>Our Cargo Ship</h2> }
CHAPTER 6
JavaScript – Introduction and Overview
Introduction to JavaScript
JavaScript is the scripting language of the Web.
JavaScript is used in millions of Web pages to add functionality, validate forms, detect
browsers, and much more.
JavaScript is used in millions of Web pages to improve the design, validate forms, detect
browsers, create cookies, and much more.
JavaScript is the most popular scripting language on the Internet, and works in all major
browsers, such as Internet Explorer, Mozilla Firefox, and Opera.
What is JavaScript?
Java and JavaScript are two completely different languages in both concept and design!
Java (developed by Sun Microsystems) is a powerful and much more complex programming language -
in the same category as C and C++.
JavaScript gives HTML designers a programming tool - HTML authors are normally not
programmers, but JavaScript is a scripting language with a very simple syntax! Almost
anyone can put small "snippets" of code into their HTML pages
JavaScript can put dynamic text into an HTML page - A JavaScript statement like this:
document.write("<h1>" + name + "</h1>") can write a variable text into an HTML page
JavaScript can react to events - A JavaScript can be set to execute when something
happens, like when a page has finished loading or when a user clicks on an HTML
element
JavaScript can read and write HTML elements - A JavaScript can read and change the
content of an HTML element
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 64
Explore Web using HTML, CSS and JavaScript
JavaScript can be used to validate data - A JavaScript can be used to validate form data
before it is submitted to a server. This saves the server from extra processing
JavaScript can be used to detect the visitor's browser - A JavaScript can be used to
detect the visitor's browser, and - depending on the browser - load another page
specifically designed for that browser
JavaScript Variables
Variables are "containers" for storing information. JavaScript variables are used to hold values or
expressions.
A variable can have a short name, like x, or a more descriptive name, like carname. Rules for
JavaScript variable names:
Variable names are case sensitive (y and Y are two different variables)
Variable names must begin with a letter or the underscore character Note: Because JavaScript is
case-sensitive, variable names are case-sensitive. Example
A variable's value can change during the execution of a script. You can refer to a variable by its
name to display or change its value.
Example
<html>
<body>
<script type="text/javascript">
var firstname;
firstname="Hello! This is first javascript code";
document.write(firstname);
</script>
</body>
</html>
Declaration
var: Declares a variable that is function-scoped or globally scoped. It's an older way to declare variables
and has some quirks due to hoisting.
var x; // Declaration
let: Declares a block-scoped variable, meaning it's limited to the block in which it is defined (like inside a
loop or an if statement).
let y; // Declaration
const: Declares a block-scoped variable that cannot be reassigned. You must initialize it at the time of
declaration.
Assignment
You can assign a value to a variable using the assignment operator =:
var x = 5; // Assigning 5 to x
let y = 10; // Assigning 10 to y
const z = 20; // z is initialized to 20 and cannot be reassigned
Examples
// Using var
var name = "Alice"; // Declaration and assignment
document.write(name); // Output: Alice
// Using let
let age = 25; // Declaration and assignment
age = 26; // Reassignment is allowed
document.write(age); // Output: 26
// Using const
const PI = 3.14; // Declaration and assignment
// PI = 3.14159; // This would throw an error because const cannot be reassigned
Document.write(PI); // Output: 3.14
Summary
Use var for function-scoped variables (generally not recommended in modern code).
Use let for block-scoped variables when you expect to change the value.
Use const for block-scoped variables when you want to prevent reassignment.
DataTypes
Numbers - are values that can be processed and calculated. You don't enclose them in quotation
marks. The numbers can be either positive or negative.
Strings - are a series of letters and numbers enclosed in quotation marks. JavaScript uses the
string literally; it doesn't process it. You'll use strings for text you want displayed or values you
want passed along.
Boolean (true/false) - lets you evaluate whether a condition meets or does not meet specified
criteria.
Null - is an empty value. null is not the same as 0 -- 0 is a real, calculable number, whereas null is
the absence of any value.
Data Types
TYPE EXAMPLE
Numbers Any number, such as 17, 21, or 54e7
Strings "Greetings!" or "Fun"
Boolean Either true or false
Null A special keyword for exactly that – the null value (that is, nothing)
Arithmetic operators are used to perform arithmetic between variables and/or values. Given that y=5,
the table below explains the arithmetic operators:
Assignment operators are used to assign values to JavaScript variables. Given that x=10 and y=5, the
table below explains the assignment operators:
In JavaScript, the + operator serves two primary purposes: addition and string concatenation.
Here's how it works in each case:
1. Addition
let a = 5;
let b = 10;
let sum = a + b; // sum will be 15
document.write(sum); // Output: 15
2. String Concatenation
3. Mixed Types
If the + operator is used with a mix of numbers and strings, JavaScript will convert numbers to
strings and concatenate:
let num = 5;
let str = " apples";
let result = num + str; // result will be "5 apples"
document.write(result); // Output: 5 apples
Summary
Addition for numbers: 5 + 10 results in 15.
Concatenation for strings: "Hello" + " World" results in "Hello World".
Mixed types result in string concatenation, with numbers converted to strings.
Comparison Operators
Comparison operators are used in logical statements to determine equality or difference between
variables or values.
Given that x=5, the table below explains the comparison operators:
Logical Operators
Logical operators are used to determine the logic between variables or values. Given that x=6 and y=3,
the table below explains the logical operators:
Conditional Operator
JavaScript also contains a conditional operator that assigns a value to a variable based on some
condition
Syntax
variablename=(condition)?value1:value2
Example
If the variable visitor has the value of "PRES", then the variable greeting will be assigned the value "Dear
President " else it will be assigned "Dear".
CHAPTER 7
JavaScript – Controls Statement, Functions
Conditional Statements
Very often when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this.
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
1. if statement
The if statement in JavaScript is used for conditional execution. It allows you to execute a block
of code if a specified condition evaluates to true. Here’s a breakdown of how it works, along
with some examples.
Basic Syntax
if (condition) {
// Code to be executed if the condition is true
}
else {
document.write ("It's a nice day!");
}
2. if statement
The switch statement in JavaScript is a control structure that allows you to execute different
blocks of code based on the value of a variable or expression. It can be a cleaner alternative to
multiple if...else if statements, especially when dealing with many conditions.
Basic Syntax
switch (expression) {
case value1:
// Code to be executed if expression === value1
break;
case value2:
// Code to be executed if expression === value2
break;
// You can add more cases as needed
default:
// Code to be executed if expression doesn't match any case
break;
}
var day = 3;
var dayName;
switch (day) {
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
case 7:
dayName = "Sunday";
break;
default:
dayName = "Invalid day";
}
document.write(dayName);
Output : Wednesday
Loops in JavaScript are used to execute a block of code repeatedly as long as a specified condition is
true. JavaScript provides several types of loops, each suited for different scenarios. Here’s a detailed
look at the various types of loops and their usage:
Loops in JavaScript
1. For Loop
The for loop is commonly used when you know how many times you want to execute a block of
code.
Syntax:
for (initialization; condition; increment) {
// Code to be executed
}
Example:
// Output:
// Iteration 0
// Iteration 1
// Iteration 2
// Iteration 3
// Iteration 4
2. While Loop
The while loop continues to execute as long as the specified condition is true. It checks the
condition before executing the code block.
Syntax:
while (condition) {
// Code to be executed
}
Example:
let i = 0;
while (i < 5) {
document.write("Iteration " + i);
i++;
}
// Output:
// Iteration 0
// Iteration 1
// Iteration 2
// Iteration 3
// Iteration 4
3. Do...While Loop
The do...while loop is similar to the while loop, but it checks the condition after executing the
code block. This means the code will run at least once.
Syntax:
do {
// Code to be executed
} while (condition);
Example:
var i = 0;
do {
console.log("Iteration " + i);
i++;
} while (i < 5);
// Output:
// Iteration 0
// Iteration 1
// Iteration 2
// Iteration 3
// Iteration 4
4. For...of Loop
The for...of loop is used to iterate over iterable objects (like arrays, strings, etc.). It provides a
simpler syntax for looping through elements.
Syntax:
Example:
// Output:
// apple
// banana
// cherry
5. For...in Loop
The for...in loop is used to iterate over the properties of an object. It is not recommended for
arrays due to potential issues with inherited properties.
Syntax:
Example:
const person = {
name: "Alice",
age: 25,
city: "New York"
};
// Output:
// name: Alice
// age: 25
// city: New York
Example:
// Output:
// 0
// 1
// 2
// 3
// 4
Example:
// Output:
// 1
// 3
// 5
// 7
// 9
Summary
JavaScript Functions
A function (also known as a method) is a self-contained piece of code that performs a particular
"function". You can recognise a function by its format - it's a piece of descriptive text, followed
by open and close brackets. A function is a reusable code-block that will be executed by an
event, or when the function is called.
To keep the browser from executing a script when the page loads, you can put your script into a
function. A function contains code that will be executed by an event or by a call to that
function.
You may call a function from anywhere within the page (or even from other pages if the
function is embedded in an external .js file).
Functions can be defined both in the <head> and in the <body> section of a document.
However, to assure that the function is read/loaded by the browser before it is called, it could
be wise to put it in the
<head> section.
Example
<html>
<head>
<script type="text/javascript">
function displaymessage()
{
alert("Hello World!");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="displaymessage()" >
</form>
</body>
</html>
If the line: alert("Hello world!!") in the example above had not been put within a function, it
would have been executed as soon as the line was loaded. Now, the script is not executed
before the user hits the button. We have added an onClick event to the button that will execute
the function displaymessage() when the button is clicked.
1. Function Declaration
A function can be declared using the function keyword followed by a name, parentheses for
parameters, and curly braces to enclose the code block.
Syntax:
function functionName(parameters) {
// Code to be executed
}
Example:
function greet(name) {
console.log("Hello, " + name + "!");
}
2. Function Expression
A function expression defines a function inside an expression. This can be anonymous (without
a name) or named.
Syntax:
Example:
3. Arrow Functions
Arrow functions provide a shorter syntax for writing function expressions. They also do not
have their own this, making them useful for certain contexts (like callbacks).
Syntax:
Example:
Functions can take parameters, which are values passed into them when they are called. You
can also set default values for parameters.
Example:
function functionname(var1,var2,...,varX)
{
some code
var1, var2, etc are variables or values passed into the function. The { and the } defines the start and end
of the function.
Note: A function with no parameters must include the parentheses () after the function name:
function functionname()
{
some code
}
Note: Do not forget about the importance of capitals in JavaScript! The word function must be written
in lowercase letters, otherwise a JavaScript error occurs! Also note that you must call a function with
the exact same capitals as in the function name.
The return statement is used to specify the value that is returned from the function. So,
functions that are going to return a value must use the return statement.
Example
The function below should return the product of two numbers (a and b):
function prod(a,b)
{
x=a*b;
return x;
}
When you call the function above, you must pass along two parameters:
product=prod(2,3);
The returned value from the prod() function is 6, and it will be stored in the variable called product.
CHAPTER 8
JavaScript – Event Handling
What is an Event?
An event is an action or occurrence recognized by the browser, which can trigger a response. Examples
include:
Event Handlers
Event Handlers are JavaScript methods, i.e. functions of objects, that allow us as JavaScript programmers to
control what happens when events occur.
Directly or indirectly, an Event is always the result of something a user does. For example, we've already seen
Event Handlers like onClick and onMouseOver that respond to mouse actions. Another type of Event, an
internal change-of-state to the page (completion of loading or leaving the page). An onLoad Event can be
considered an indirect result of a user action.
Although we often refer to Events and Event Handlers interchangeably, it's important to keep in mind the
distinction between them. An Event is merely something that happens - something that it is initiated by an
Event Handler (onClick, onMouseOver, etc...).
The elements on a page which can trigger events are known as "targets" or "target elements," and we can
easily understand how a button which triggers a Click event is a target element for this event. Typically,
events are defined through the use of Event Handlers, which are bits of script that tell the browser what to
do when a particular event occurs at a particular target. These Event Handlers are commonly written as
attributes of the target element's HTML tag.
The Event Handler for a Click event at a form field button element is quite simple to understand:
The event_handler_code portion of this example is any valid JavaScript and it will be executed when the
specified event is triggered at this target element. This particular topic will be continued in Incorporating
JavaScripts into your HTML pages.
There are "three different ways" that Event Handlers can be used to trigger Events or Functions.
Places an Event Handler as an attribute within an <A HREF= > tag, like this:
You can use an Event Handler located within an <A HREF= > tag to make either an image or a text link
respond to a mouseover Event. Just enclose the image or text string between the <A HREF= > and the
</A> tags.
Whenever a user clicks on a link, or moves her cursor over one, JavaScript is sent a Link Event. One Link Event
is called onClick, and it gets sent whenever someone clicks on a link. Another link event is called
onMouseOver. This one gets sent when someone moves the cursor over the link.
You can use these events to affect what the user sees on a page. Here's an example of how to use link
events. Try it out, View Source, and we'll go over it.
<A HREF="javascript:void('')"
onClick="open('index.htm', 'links', 'height=200,width=200');">How to Use Link Events
</A>
The first interesting thing is that there are no <SCRIPT> tags. That's because anything that appears in the
quotes of an onClick or an onMouseOver is automatically interpreted as JavaScript. In fact, because
semicolons mark the end of statements allowing you to write entire JavaScripts in one line, you can fit an
entire JavaScript program between the quotes of an onClick. It'd be ugly, but you could do it.
In the first example we have a normal <A> tag, but it has the magic onClick="" element, which says, "When
someone clicks on this link, run the little bit of JavaScript between my quotes." Notice, there's even a
terminating semicolon at the end of the alert. Question: is this required? NO.
HREF="#" tells the browser to look for the anchor #, but there is no anchor "#", so the browser
reloads the page and goes to top of the page since it couldn't find the anchor.
<A HREF="javascript:void('')" tells the browser not to go anywhere - it "deadens" the link when you
click on it.
HREF="javascript: is the way to call a function when a link (hyperlink or an HREFed image) is clicked.
HREF="javascript:alert('Ooo, do it again!')" here we kill two birds with one stone. The default
behavior of a hyperlink is to click on it. By clicking on the link we call the window Method alert() and
also at the same time "deaden" the link.
This is just like the first line, but it uses an onMouseOver instead of an onClick.
The second technique we've seen for triggering a Function in response to a mouse action is to place an
onClick Event Handler inside a button type form element, like this:
<FORM>
<INPUT TYPE="button" onClick="doSomething()">
</FORM>
While any JavaScript statement, methods, or functions can appear inside the quotation marks of an Event
Handler, typically, the JavaScript script that makes up the Event Handler is actually a call to a function
defined in the header of the document or a single JavaScript command. Essentially, though, anything that
appears inside a command block (inside curly braces {}) can appear between the quotation marks.
For instance, if you have a form with a text field and want to call the function checkField() whenever the
value of the text field changes, you can define your text field as follows:
Nonetheless, the entire code for the function could appear in quotation marks rather than a function call:
The advantage of using functions as Event Handlers, however, is that you can use the same Event Handler
code for multiple items in your document and, functions make your code easier to read and understand.
The third technique is to us an Event Handler to ensure that all required objects are defined involve
the onLoad and onUnLoad. These Event Handlers are defined in the <BODY> or <FRAMESET> tag of
an HTML file and are invoked when the document or frameset are fully loaded or unloaded. If you
set a flag within the onLoad Event Handler, other Event Handlers can test this flags to see if they can safely
run, with the knowledge that the document is fully loaded and all objects are defined.
For example:
<SCRIPT>
var loaded = false;
function doit() {
// alert("Everything is \"loaded\" and loaded = " + loaded);
alert('Everything is "loaded" and loaded = ' + loaded);
}
</SCRIPT>
<BODY onLoad="loaded = true;">
-- OR --
<FORM>
<INPUT TYPE="button" VALUE="Press Me"
onClick="if (loaded == true) doit();">
-- OR --
-- OR --
</BODY>
The onLoad Event Handler is executed when the document or frameset is fully loaded, which means that all
images have been downloaded and displayed, all subframes have loaded, any Java Applets and Plugins
(Navigator) have started running, and so on. The onUnLoad Event Handler is executed just before the page is
unloaded, which occurs when the browser is about to move on to a new page. Be aware that when you are
working with multiple frames, there is no guarantee of the order in which the onLoad Event Handler is
invoked for the various frames, except that the Event Handlers for the parent frame is invoked after the
Event Handlers of all its children frames -- This will be discussed in detail in Week 8.
<html>
<head>
<script>
function doAdd()
{
a=document.f1.aa.value;
b=document.f1.bb.value;
c=a+b;
document.write(" <h2> ADD= "+c);
}
</script>
</head>
<body>
<h1> ADD two number </h1>
<form name="f1">
<h2>
Enter 1st no=
<input type="text" name="aa">
</h2>
<h2>
Enter 2nd no=
<input type="text" name="bb">
</h2>
<h2>
Click to get add
<input type="submit" name="cc" value="add" onClick="doAdd()">
</h2>
</form>
</body>
<html>
<script>
function findNow()
{
n=document.f1.aa.value;
n=parseInt(n);
for(i=1;i<=10;i++)
{
t=n*i;
document.write(" <h2> "+n+" x "+i+" = "+t);
}
</script>
<body>
<form name="f1">
<h2> Find the Multiplication Table </h2>
<h3> Enter any number
<input type="text" name="aa">
</h3>
</form>
</body>
</html>
<html>
<script>
function findSquare()
{
n=document.f1.aa.value;
n=parseInt(n);
v = n*n;
document.write(" <h2> “+ v+ “</h2>”);
</script>
<body>
<form name="f1">
<h2> Find the Square </h2>
<h3> Enter any number
<input type="text" name="aa">
</h3>
</form>
</body>
</html>
CHAPTER 9
JavaScript – DOM Manipulations,
Form Validations
DOM manipulation in JavaScript refers to the process of dynamically changing the structure, style, or content
of a web page. The Document Object Model (DOM) represents the document as a tree of objects, allowing
you to interact with HTML elements using JavaScript. Here’s a breakdown of the key methods and
techniques for DOM manipulation:
Selecting Elements
1. getElementById: Selects an element by its ID.
3. getElementsByTagName: Selects elements by their tag name (also returns a live HTMLCollection).
4. querySelector: Selects the first element that matches a specified CSS selector.
5. querySelectorAll: Selects all elements that match a specified CSS selector (returns a static
NodeList).
Modifying Elements
1. Changing Text Content:
3. Changing Attributes:
element.setAttribute('src', 'newImage.png');
4. Changing Styles:
element.style.color = 'red';
element.style.backgroundColor = 'blue';
2. Appending Elements:
document.body.insertBefore(newElement, referenceNode);
4. Removing Elements:
elementToRemove.remove();
<!DOCTYPE html>
<html lang="en">
<head>
<title>Change Background Color</title>
<style>
#colorBox {
width: 200px;
height: 200px;
background-color: lightblue; /* Initial background color */
border: 1px solid #000;
}
</style>
<script>
function changeBack()
{
// JavaScript to change the background color
var box = document.getElementById('colorBox');
box.style.backgroundColor = "green";
}
</script>
</head>
<body>
<div id="colorBox"></div>
<button id="changeColorBtn" onclick="changeBack()">Change Color</button>
</body>
</html>
JavaScript provides facility to validate the form on the client-side so data processing will be faster than
server-side validation. Most of the web developers prefer JavaScript form validation.
Through JavaScript, we can validate name, password, email, date, mobile numbers and more fields.
In this example, we are going to validate the name and password. The name can’t be empty and password can’t be less
than 6 characters long.
Here, we are validating the form on form submit. The user will not be forwarded to the next page until given values are
correct.
<script>
function validateform(){
var name=document.myform.name.value;
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else{
return true;
}
}
</script>
<body>
<form name="myform" method="post" action="abc.jsp" onsubmit="return validateform()" >
Name: <input type="text" name="name"><br/>
<input type="submit" value="register">
</form>
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 100
Web Tools using HTML,CSS and Javascript 2024
<script type="text/javascript">
function matchpass(){
var firstpassword=document.f1.password.value;
var secondpassword=document.f1.password2.value;
if(firstpassword==secondpassword){
return true;
}
else{
alert("password must be same!");
return false;
}
}
</script>
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 101
Web Tools using HTML,CSS and Javascript 2024
Let's validate the textfield for numeric value only. Here, we are using isNaN() function.
<script>
function validate(){
var num=document.myform.num.value;
if (isNaN(num)){
document.getElementById("numloc").innerHTML="Enter Numeric value only";
return false;
}else{
return true;
}
}
</script>
<form name="myform" onsubmit="return validate()" >
Number: <input type="text" name="num"><span id="numloc"></span><br/>
<input type="submit" value="submit">
</form>
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 102
Web Tools using HTML,CSS and Javascript 2024
<script>
function validateemail()
{
var x=document.myform.email.value;
var atposition=x.indexOf("@");
var dotposition=x.lastIndexOf(".");
if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length){
alert("Please enter a valid e-mail address \n atpostion:"+atposition+"\n dotposition:"+dotposition);
return false;
}
}
</script>
<body>
<form name="myform" method="post" action="#" onsubmit="return validateemail();">
Email: <input type="text" name="email"><br/>
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 103
Web Tools using HTML,CSS and Javascript 2024
CHAPTER 10
JavaScript – Lab Assignments
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 104
Web Tools using HTML,CSS and Javascript 2024
1.2 Modify the above program to compute AREA of triangle where inputs will be
ENTER LENGTH 10
ENTER BREADTH 8
Output will be
AREA OF TRIANGLE IS 9
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 105
Web Tools using HTML,CSS and Javascript 2024
2. 1 Create a simple Calculator to addition with ADD button, using form atrributes
Use the onClick event to get the addition total as show below.
2.2 You can later modify to implement more buttons with SUBTRACT, MULTIPLY and DIVIDE.
3 Compute the Area and Perimeter of Rectangle with the given interface below:
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 106
Web Tools using HTML,CSS and Javascript 2024
4 Change the background color of the box using dropdown (select tag)
If you choose Red from the option then background color should change to Red
You should also validate the dropdown if option chosen then it should give alert message ‘No
Option Chosen’
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 107
Web Tools using HTML,CSS and Javascript 2024
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 108
Web Tools using HTML,CSS and Javascript 2024
If any textbox remains blank then give an alert message ‘Fields cannot be blank’ otherwise
display ‘Registration Done’
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 109
Web Tools using HTML,CSS and Javascript 2024
If no option chosen then give an alert message ‘Choose at least one item’
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 110
Web Tools using HTML,CSS and Javascript 2024
9.3 Also the above task implement CSS design with hover button
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 111
Web Tools using HTML,CSS and Javascript 2024
10.1 Create a submit button with input of your name and validate it
10.2 Add also age and phone and validate the field with JavaScript on the above, i.e, 10.1
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 112
Web Tools using HTML,CSS and Javascript 2024
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 113
Web Tools using HTML,CSS and Javascript 2024
11.2 Create a banner which will come with SetTimeout and array images
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 114
Web Tools using HTML,CSS and Javascript 2024
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 115
Web Tools using HTML,CSS and Javascript 2024
13.1 Create two texts BRAINWARE and UNIVERSITY in div like this and once they come closer
to each other it will print Best No. 1 University.
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 116
Web Tools using HTML,CSS and Javascript 2024
13.2 Create now four texts in four directions of each positions of the browsers in different
four colours. and all come to center and gives a message WELCOME BRAINWARE
UNIVERSITY.
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 117
Web Tools using HTML,CSS and Javascript 2024
14. After the checkbox done in 12.2 do the following events and output with Javascript as
shown below:
Once you check custom clearance the output will be as given below:
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 118
Web Tools using HTML,CSS and Javascript 2024
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 119
Web Tools using HTML,CSS and Javascript 2024
I would like to express my heartfelt gratitude to everyone who has supported me throughout the journey of
authoring Explore Web: HTML, CSS, and JavaScript for B.Tech., BCA, and MCA students.
This book is the culmination of over 25 years of experience in the field of web development, and it wouldn't
have been possible without the encouragement and contributions of my students, colleagues, and parents.
To my students: Your curiosity and dedication to learning have always inspired me to dive deeper and strive
for excellence. When a reputed corporate company invited me write a specific book for its employees/trainees,
it is at this juncture, inspired me to begin this book which of course needs more scope of development in terms
of more examples and elaborations of the topics. This books is not a bible of Web Tools but a pocket bible for
all Web Developers and who are novice to IT skills and Web Tools. You are really inspired me to pen this
book for your better subject knowledge.
To my colleagues: Your collaboration and insights have been invaluable in refining the concepts and approach
presented in this book. Riya Jana particularly was always there for my codes and debugs to be processed in
most easiest manner and it is great to have this kind of colleagues who can always act as an interpreter.
Thank you all for being a part of this journey. I hope this book serves as a comprehensive guide for students
exploring the fascinating world of web development.
Warm regards,
Saugata Sarkar
29/09/2024
Copyright reserved with Saugata Sarkar @ Onward Academy @ 2024 Page 120