Web LAB Manual 2024-25
Web LAB Manual 2024-25
LABORATORY MANUAL
Semester : V
Subject : Web Technology Laboratory
Subject Code : BCSL504
NAME:
USN:
SECTION:
Web Technology Lab (BCSL504)
PROGRAM OUTCOMES
PO2: Problem analysis: Identify, formulate, review research literature, and analyse complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO11: Project management and finance: Demonstrate knowledge and understanding of the
Engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
PO12: Life -long learning: Recognize the need for and have the preparation and ability to
VISION
The East Point College of Engineering and Technology aspires to be a globally acclaimed
institution, recognized for excellence in engineering education, applied research and nurturing
students for holistic development.
MISSION
M1: To create engineering graduates through quality education and to nurture innovation,
creativity and excellence in teaching, learning and research
M2: To serve the technical, scientific, economic and societal developmental needs of our
communities
M3: To induce integrity, teamwork, critical thinking, personality development and ethics in
students and to lay the foundation for lifelong learning
VISION
MISSION
M2: To augment experiential learning skills to serve technical, scientific, economic, and social
developmental needs.
M3: To instil integrity, critical thinking, personality development, and ethics in students for a
successful career in Industries, Research, and Entrepreneurship.
PEO 1: To produce graduates who can perform technical roles to contribute effectively in
software industries and R&D Centre.
PEO 2: To produce graduates having the ability to adapt and contribute in key domains of
computer science and engineering to develop competent solutions.
PEO 3: To produce graduates who can provide socially and ethically responsible solutions
while adapting to new trends in the domain to carve a successful career in the industry.
PSO1: To conceptualize, model, design, simulate, analyse, develop, test, and validate
computing systems and solve technical problems arising in the field of computer science &
engineering.
PSO2: To specialize in the sub-areas of computer science & engineering systems such as
cloud computing, Robotic Process Automation, cyber security, big data analytics, user interface
design, and IOT to meet industry requirements.
PSO3: To build innovative solutions to meet the demands of the industry using appropriate
COURSE OUTCOMES
Web technology refers to the tools, frameworks, and techniques used to create, manage, and operate
websites and web applications. It encompasses various components that enable the development,
deployment, and functioning of the World Wide Web. Key aspects of web technology include:
1. Front-end technologies: These are tools used to create the client-side (what users see and
interact with in a browser), including:
• HTML (Hypertext Markup Language) for structuring content.
• CSS (Cascading Style Sheets) for styling and layout.
• JavaScript for interactive and dynamic elements.
2. Back-end technologies: These manage server-side operations (behind-the-scenes
functionality), including:
• Server-side scripting languages like PHP, Python, Ruby, and Node.js.
• Databases like MySQL, MongoDB, and PostgreSQL to store and manage data.
• Web servers like Apache and Nginx.
3. Web protocols and standards: These ensure smooth communication between servers and
clients, such as:
• HTTP/HTTPS (Hypertext Transfer Protocol) for transferring web pages.
• WebSockets for real-time, bidirectional communication.
• RESTful APIs for interaction between front-end and back-end services.
4. Web development frameworks: These simplify the creation of web applications:
• Front-end frameworks like React, Angular, and Vue.js.
• Back-end frameworks like Django, Flask, Ruby on Rails, and Express.js.
5. Web hosting: This involves storing website files on servers and making them accessible on
the internet.
Web Applications:
A web application is a software application that runs on a web server and can be accessed through a
web browser using the internet. Unlike traditional desktop applications, which are installed on a local
computer, web applications are accessed remotely and require only a browser to operate, making
WWW:
WWW stands for the World Wide Web, which is a system of interlinked hypertext documents and
multimedia content that can be accessed via the internet. When a user accesses the web using a
browser, they can view web pages that may contain text, images, videos, and other media, as well as
links to other pages.
Key components of the World Wide Web include:
1. Web Pages: These are documents written in HTML (Hypertext Markup Language) and are
displayed by web browsers like Chrome, Firefox, or Safari.
2. Web Browsers: Software applications that allow users to access and navigate the web (e.g.,
Chrome, Firefox, Edge).
3. URLs (Uniform Resource Locators): The web address used to locate a web page or
resource on the internet (e.g., https://www.example.com).
4. HTTP/HTTPS: Protocols used to request and transfer data over the web. HTTPS adds a
layer of security (encryption) to the connection.
5. Hyperlinks: Links between different web pages or websites, allowing users to navigate the
vast content on the web.
Web site: A set of interconnected web pages, usually including a homepage, generally located on the
same server, and prepared and maintained as a collection of information by a person, group, or
organization.
Types of Web Pages:
• Static web page: is delivered exactly as stored, as web content in the web server's file
system. Contents cannot be changed.
• Dynamic web page: is generated by a web application that is driven by server-side software
INTRODUCTION TO HTML
HTML (HyperText Markup Language) is the standard language used to create and design web
pages. It provides the structure for a web page by defining elements like headings, paragraphs,
images, links, and more. HTML is not a programming language but a markup language that uses
tags to annotate text, images, and other content, making it interpretable by web browsers.
HTML was developed by Tim Berners-Lee in 1991 and is currently maintained by the World
Wide Web Consortium (W3C). Modern HTML (HTML5) also supports multimedia, interactive
features, and responsive design.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph of text.</p>
<img src="image.jpg" alt="Description of image">
<a href="https://example.com">This is a link</a>
</body>
</html>
HTML Elements
HTML documents are made up of elements. An HTML element consists of:
o Opening tag: <tagname>
o Content: Between the opening and closing tag (optional for some tags)
o Closing tag: </tagname>
For example:
<p>This is a paragraph.</p>
Uses of HTML
• Webpage Structure: HTML provides the foundational structure for all web pages
and applications. It defines the layout of content and ensures web browsers display
the text, images, and interactive elements correctly.
• Hyperlinks: HTML enables links between pages on the web, creating the
interconnected nature of the World Wide Web.
• Multimedia Integration: Modern HTML (HTML5) supports embedding multimedia
elements such as audio, video, and interactive games directly into web pages.
• Form Handling: HTML forms enable user interaction, like logging in, submitting
data, or making online purchases.
• Responsive Design: HTML5 includes new elements like <header>, <footer>,
<article>, and <section>, which enhance the structure and accessibility of web
pages, making them easier to style responsively.
Using CSS
CSS can be added to HTML documents in 3 ways:
a) Inline - by using the style attribute inside HTML elements
b) Internal - by using a <style> element in the <head> section
c) External - by using a <link> element to link to an external CSS file
a)Inline CSS:
• An inline CSS is used to apply a unique style to a single HTML element.
• An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and the text color of the
<p> element to red:
Example: <h1 style="color:blue;">A Blue coloured Heading</h1>
<p style=" background-color:lightblue;font-family:calibri;font-size:20px;">A red
paragraph.</p>
b)Internal CSS:
• An internal CSS is used to define a style for a single HTML page.
• An internal CSS is defined in the <head> section of an HTML page, within
a <style> element.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph. </p>
</body>
</html>
External CSS
JavaScript
JavaScript (js) is a light-weight object-oriented programming language which is used by several
websites for scripting the webpages. It is an interpreted, full-fledged programming language
that enables dynamic interactivity on websites when applied to an HTML document. It was
introduced in the year 1995 for adding programs to the webpages in the Netscape Navigator
browser. Since then, it has been adopted by all other graphical web browsers. With JavaScript,
users can build modern web applications to interact directly without reloading the page every
time. The traditional website uses js to provide several forms of interactivity and simplicity.
Although, JavaScript has no connectivity with Java programming language. The name was
suggested and provided in the times when Java was gaining popularity in the market. In addition
to web browsers, databases such as CouchDB and MongoDB uses JavaScript as their scripting
and query language.
Features of JavaScript
There are following features of JavaScript:
1. All popular web browsers support JavaScript as they provide built-in execution
environments.
2. JavaScript follows the syntax and structure of the C programming language. Thus, it
is a structured programming language.
3. JavaScript is a weakly typed language, where certain types are implicitly cast
(depending on the operation).
4. JavaScript is an object-oriented programming language that uses prototypes rather
than using classes for inheritance.
5. It is a light-weighted and interpreted language.
6. It is a case-sensitive language.
7. JavaScript is supportable in several operating systems including, Windows, macOS,
etc.
8. It provides good control to the users over the web browsers.
Applications of JavaScript
1. Client-Side Scripting: JavaScript runs in the user's web browser, allowing for
immediate interaction with web pages without needing to communicate with the
server.
Note: Scripts can be placed in the <body>, or in the <head> section of an HTML page, or
in both.
JavaScript in <head>
In this example, a JavaScript function is placed in the <head> section of an HTML page.
The function is invoked (called) when a button is clicked:
Example
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
JavaScript Output
JavaScript can "display" data in different ways:
• Writing into an HTML element, using innerHTML: To access an HTML element,
JavaScript can use the document.getElementById(id) method.
The id attribute defines the HTML element. The innerHTML property defines the
HTML content:
document.getElementById("demo").innerHTML = “hello”;
PHP
PHP (Hypertext Preprocessor) is a popular server-side scripting language designed for web
development. It is embedded within HTML and executed on the server to generate dynamic
web content based on user interactions or data. PHP excels in creating interactive and data-
driven websites, offering robust support for database integration and session management.
Being open-source and platform-independent, PHP is widely used by developers for its ease of
use, extensive community support, and ability to handle complex server-side tasks efficiently.
PHP syntax is designed to be simple and flexible, allowing for easy integration with
HTML and providing powerful scripting capabilities. Below is a quick guide to
understanding PHP syntax.
1. Basic PHP Syntax
• PHP Code Block: PHP code is written between <?php ... ?> tags.
• Echo Statement: echo is used to output text or variables to the browser.
<?php
echo "Hello, World!";
?>
• Comments:
o Single-line comments: // or #
o Multi-line comments: /* ... */
2. Variables
• Variables in PHP start with a $ symbol, followed by the variable name.
• PHP variables are dynamically typed, meaning they don’t require explicit type
declarations.
<?php
$name = "Alice";
Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Web Page</title>
</head>
<body>
<!-- Moving Text -->
<marquee>Basic HTML Tags</marquee>
<!-- Different Heading Tags -->
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<!-- Paragraph -->
<p>This is a paragraph demonstrating basic HTML tags and their usage.</p>
<!-- Horizontal Line -->
<hr>
<!-- Line Break -->
This is some text. <br> This is the next line after a line break.
<!-- Block Quote -->
<blockquote>
"This is a block quote, usually used for quoting someone or something significant."
</blockquote>
EXPERIMENT 2
Develop the HTML page named as “Table.html” to display your class time table.
a) Provide the title as Time Table with table header and table footer, row-span and col-span
etc.
b) Provide various colour options to the cells (Highlight the lab hours and elective hours
with different colours.)
c) Provide colour options for rows.
Program
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Time Table</title>
<style>
table {
width: 60%;
border-collapse:collapse;
text-align: center;
}
th, td {
border: 2px solid black;
padding: 10px;
}
th {
background-color: rgb(135, 2, 71);
color: white;
}
thead th{background-color: rgb(57, 132, 61);}
tfoot td {
background-color: rgb(150, 234, 136);
font-weight: bold;
}
.lab {
background-color: lightcoral; /* Highlight lab hours */
}
.elective {
background-color: rgba(119, 53, 233, 0.4); /* Highlight elective hours */
}
tr:nth-child(even) {
<table>
<thead>
<tr>
<th colspan="9">Time Table</th>
</tr>
</thead>
<tr>
<th>Day</th>
<th>8:45 - 9:45</th>
<th>9:45 - 10:45</th>
<th>10:45 - 11:00</th>
<th>11:00 - 12:00</th>
<th>12:00 - 1:00</th>
<th>1:00 - 1:45</th>
<th>1:45 - 2:45</th>
<th>2:45 - 3:45</th>
</tr>
<tbody>
<tr>
<td>Monday</td>
<td>TOC</td>
<td class="elective">Elective: AI</td>
<td rowspan="5">BREAK</td>
<td>CN</td>
<td>EVS</td>
<td rowspan="5">BREAK</td>
<td>SE</td>
<td>RM</td>
</tr>
<tr>
EXPERIMENT 3
Develop an external style sheet named as “style.css” and provide different styles for h2,
h3, hr, p, div, span, time, img & a tags. Apply different CSS selectors for tags and
demonstrate the significance of each.
style.css:
</body>
</html>
Sample Output:
h1 {
color: darkblue;
text-align: center;
}
form {
background-color: #fff;
border-radius: 10px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 700px;
margin: auto;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
table td {
padding: 10px;
}
.highlight {
background-color: #d3f0d1;
}
input[type="submit"]:hover, input[type="reset"]:hover {
background-color: blue;
}
td {
vertical-align: top;
}
HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>University Student Registration</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<table>
<tr>
<td><input type="submit" value="Submit"></td>
<td><input type="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
Sample Output:
EXPERIMENT 5
Develop HTML page named as “newpaper.html” having variety of HTML semantic
elements with background colors, text-colors & size for figure, table, aside, section,
article, header, footer… etc.
In HTML there are some semantic elements that can be used to define different parts of a web
page. Semantic tags in HTML are elements that clearly describe their meaning in a human- and
machine-readable way. These tags provide additional information about the content they
contain, making it easier for browsers, developers, and assistive technologies to understand the
structure and purpose of the content.
❖ Semantic tags help screen readers and other assistive devices to better interpret content
for users with disabilities.
❖ Code becomes more readable and maintainable for developers, making it easier to
understand the structure of the page at a glance.
• <article>
• <aside>
• <details>
• <figcaption>
• <figure>
• <footer>
• <header>
• <main>
• <mark>
• <nav>
• <section>
• <summary>
• <time>
/* General styling */
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
background-color: #f0f0f0;
}
h1, h2, h3 {
color: darkblue;
margin-bottom: 10px;
}
p{
color: #333;
font-size: 18px;
}
/* Header styling */
header {
background-color: navy;
color: white;
padding: 10px 0;
text-align: center;
}
header nav ul {
list-style: none;
padding: 0;
}
header nav ul li {
display: inline;
margin: 0 10px;
}
header nav ul li a {
color: white;
text-decoration: none;
font-weight: bold;
}
section {
flex: 70%;
background-color: white;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
aside {
flex: 25%;
background-color: #f9f9f9;
padding: 20px;
margin-left: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
aside h3 {
color: darkgreen;
font-size: 20px;
}
aside ul {
list-style-type: square;
margin: 0;
padding: 0;
}
aside ul li {
margin-bottom: 10px;
}
/* Table styling */
table {
width: 100%;
table th {
background-color: #4CAF50;
color: white;
}
table tr:nth-child(even) {
background-color: #f2f2f2;
}
/* Footer styling */
footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px 0;
margin-top: 20px;
}
footer a {
color: lightblue;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
figure img {
border: 3px solid #ddd;
border-radius: 10px;
}
figcaption {
font-size: 16px;
color: #555;
}
Newspaper.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bangalore News</title>
<link rel="stylesheet" href="newspaper-style.css">
</head>
<body>
<article>
<h2>Local News: Cubbon Park Renovation</h2>
<p>The Bangalore City Corporation has announced a major renovation of Cubbon
Park, one of the city's most beloved green spaces. The project will introduce eco-friendly
lighting, improved walking paths, and better security features.</p>
<figure>
<img src="cubbon-park.jpg" alt="Cubbon Park Bangalore" width="400">
<figcaption>Ongoing Renovation at Cubbon Park</figcaption>
</figure>
<p>Residents are excited about the initiative, which aims to maintain the park’s
natural beauty while making it safer and more accessible for visitors.</p>
</article>
<article>
<h2>World News: Bangalore Joins Global Climate Summit</h2>
<p>As a major tech hub, Bangalore is participating in the Global Climate Summit.
The city's efforts in promoting renewable energy and reducing carbon emissions have gained
international recognition. The government is pushing for green initiatives in IT parks and
residential areas.</p>
</article>
</section>
<h3>Weather Report</h3>
<p>Sunny with a chance of rain. High of 29°C, low of 20°C. Typical Bangalore
weather for this time of year, so be prepared for unexpected showers!</p>
</aside>
</main>
Sample Output:
Apply HTML, CSS and JavaScript to design a simple calculator to perform the following
operations: sum, product, difference, remainder, quotient, power, square-root and
square.
Calculator.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="calculator">
<h1>Simple Calculator</h1>
<form id="calculator-form">
<input type="number" id="num1" placeholder="Enter first number" required>
<input type="number" id="num2" placeholder="Enter second number" required>
<select id="operation">
<option value="sum">Sum</option>
<option value="product">Product</option>
<option value="difference">Difference</option>
<option value="remainder">Remainder</option>
<option value="quotient">Quotient</option>
<option value="power">Power</option>
<option value="square-root">Square Root</option>
<option value="square">Square</option>
</select>
<button type="button" onclick="calculate()">Calculate</button>
</form>
<div id="result">
<h2>Result:</h2>
<p id="output">Please enter numbers and select an operation.</p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Calculator-styles.css:
JavaScript Objects :Objects are variables in javascript. But objects can contain many
values.
CSV(comma-separated values): A .csv file is a text file format that stores data in a table
structure, with commas separating values and newlines separating records.
Html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Conversion and Hashing Tool</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
textarea, input, button {
margin: 10px 0;
padding: 10px;
width: 100%;
max-width: 500px;
}
button {
cursor: pointer;
}
pre {
background: #f4f4f4;
padding: 10px;
white-space: pre-wrap;
}
</style>
</head>
<body>
<script>
// Function to convert JSON text to a JavaScript Object
function convertJsonToObject() {
const jsonInput = document.getElementById('jsonInput').value;
try {
const jsonObject = JSON.parse(jsonInput);
document.getElementById('jsonObjectOutput').textContent =
JSON.stringify(jsonObject, null, 2);
} catch (error) {
document.getElementById('jsonObjectOutput').textContent = 'Invalid JSON input.';
}
}
</body>
</html>
Sample output:
EXPERIMENT 8
8. a) Develop a PHP program (with HTML/CSS) to keep track of the number of visitors
visiting the web page and to display this count of visitors, with relevant headings.
b) Develop a PHP program (with HTML/CSS) to sort the student records which are
stored in the database using selection sort.
a. PHP Program to Track and Display the Number of Visitors
Steps to follow:
Step 1: Set Up Your Project Files
1. Create a New Folder for your project in Visual Studio Code.
2. Inside this folder, create:
o index.php: This will contain your PHP and HTML code.
o visitor_count.txt: An empty file where the visitor count will be stored.
o phpStyle.css (optional): Any CSS you want to style your page.
Step 2: Save Your PHP and HTML Code in index.php
Step 3: Run the PHP File with a Local Server
1. Open the Integrated Terminal in Visual Studio Code by selecting View > Terminal.
2. Start PHP’s Built-In Server by navigating to the folder where index.php is saved and
running:
php -S localhost:8000
index.php:
<?php
// File to store the visitor count
$counterFile = 'visitor_count.txt';
// Check if the counter file exists
if (!file_exists($counterFile)) {
// If not, create the file and initialize the count to 0
file_put_contents($counterFile, '0');
}
// Read the current count
$visitorCount = (int)file_get_contents($counterFile);
// Increment the count
$visitorCount++;
// Write the new count back to the file
file_put_contents($counterFile, $visitorCount);
?>
styles.css:
Steps:
Step 1: Start MySQL Server
1. Open MySQL:
o If you’re using MySQL Workbench, launch it and connect to your MySQL
server.
o If you’re using the command line, open a terminal and type: mysql -u root -p
o Enter your MySQL root password to access the MySQL prompt.
db_config.php:
<?php
$servername = "localhost";
$username = "root"; // Update with your database username
$password = ""; // Update with your database password
$dbname = "school";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
sort_students.php
<?php
include 'db_config.php';
// Fetch student records
$sql = "SELECT id, name, score FROM students";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$students = [];
// Store all student records in an array
while ($row = $result->fetch_assoc()) {
$students[] = $row;
}
// Selection sort algorithm to sort by score in descending order
$n = count($students);
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sorted Student Records</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Sorted Student Records</h1>
<?php if (empty($students)): ?>
<p>No student records found.</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php foreach ($students as $student): ?>
<tr>
/* Table styling */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table th, table td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
table th {
background-color: #4CAF50;
color: white;
}
table tr:nth-child(even) {
background-color: #f2f2f2;
}
Output:
Develop jQuery script (with HTML/CSS) for: a. Appends the content at the end of the
existing paragraph and list. b. Change the state of the element with CSS style using
animate () method c. Change the color of any div that is animated.
Instructions: Create a new folder to keep .html, .js and .css file. The execute .html file.
button:hover {
background-color: #45a049;
}
$("#appendListBtn").click(function() {
const listItemText = $("#listInput").val();
if (listItemText) {
$("#myList").append("<li>" + listItemText + "</li>");
$("#listInput").val(""); // Clear the input field
} else {
alert("Please enter text to add to the list.");
}
});
EXPERIMENT 10
Develop a JavaScript program with Ajax (with HTML/CSS) for: a. Use ajax() method
(without Jquery) to add the text content from the text file by sending ajax request. b. Use
ajax() method (with Jquery) to add the text content from the text file by sending ajax
request. c. Illustrate the use of getJSON() method in jQuery d. Illustrate the use of
parseJSON() method to display JSON values.
HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AJAX and JSON Examples</title>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="script.js" defer></script>
</head>
<body>
<div class="container">
<h1>AJAX and JSON with JavaScript and jQuery</h1>
function loadTextWithoutJQuery() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "textfile.txt", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
// Replace content instead of appending
document.getElementById("textWithoutJQuery").innerText = xhr.responseText;
}
};
xhr.send();
}
$(document).ready(function() {
$("#loadTextWithJQuery").click(function() {
$.ajax({
url: "textfile.txt",
type: "GET",
success: function(data) {
// Replace content instead of appending
$("#textWithJQuery").text(data);
},
error: function() {
$("#textWithJQuery").text("Failed to load content.");
}
$("#parsedJsonData").html(output);
});
});
Stylesheet:style.css
/* Styling for container and buttons */
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: #f5f5f5;
}
.container {
text-align: center;
button {
margin: 10px 0;
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 8px;
font-size: 0.9em;
cursor: pointer;
width: 100%;
}
button:hover {
background-color: #45a049;
}
div {
margin: 10px 0;
padding: 10px;
border: 1px solid #ddd;
border-radius: 6px;
background-color: #f9f9f9;
}
Textfile:textfile.txt
Welcome to our website! Here’s some information loaded dynamically using AJAX.
JSON file:data.json
{
"name": "Alice",
"age": 30,
"city": "Los Angeles"
}
****************************************************************