Web Technology Lab Manual for BE Students
Web Technology Lab Manual for BE Students
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING
LABORATORY MANUAL
B.E V SEMESTER
(CBCS SCHEME)
WEB TECHNOLOGY
Lab Manual
Name: ……………………………………………………..….
Branch: ………………………………………………….……
USN: ……………………………….……………………….…
2
PREFACE
In the current digital age,, web based technologies have become an integral part of bridging the gap
between people, organization and information throughout the world. It is important to note that
knowledge of web technologies is necessary for making applications that are rich, interactive and
easy to use by the end users. The aim of developing Web Technology Lab manual is to provide an in-
depth understanding of the basic concepts as well as hands-on skills necessary for developing
working websites.
This lab emphasizes both the basic principles and modern techniques employed in web building. It
ranges from simple static web pages creating using basic HTML and CSS covering the addition of
more complex dynamic features with JavaScript and AJAX. Additionally detailed information on
client and server communication, database usage and application of web frameworks like Django for
development will be provided for students.
Using HTML5 and CSS3 to build both static and dynamic web pages
Increasing the interactivity of users with JavaScript, AJAX and jQuery
Fielding the new web standards of system display and web usability
Surveying content repository behavior for dynamic resource presentation
As a result of this laboratory work, students will have the hands-on skills to construct web solutions
in their entirety. In addition, they will be able to design, build and deploy a web application.
3
Department of Computer science
ABOUT
The department of Computer Science and Engineering was established in the year [Link] department
offer undergraduate programmed in Computer Science & Engineering. The department has a very good
infrastructure and faculty to provide excellent education to meet the industry standards.
Today, the department caters to the needs of more than 60 UG Students. It houses state of the art
computing facilities with high end servers which support the LAN, provide a Linux/Unix environment,
also provides exclusive library facility to its students and boasts of well trained and experienced faculty
teaching the departments various courses in the areas of Computer Networks, Computer Architecture,
Database Systems, Microprocessor, Operating Systems, Analysis and Design of Algorithms and Software
Engineering.
The department lays stress on the practical and application based aspects through laboratories, seminars,
group discussions, viva-vice and project work, keeping pace with the growth in Computer Science &
Engineering technology.
The Students are given scope to conduct experiments on innovative ideas. A sound theoretical and
practical work prepares the students in wider field of Computer Science & Engineering to take up
challenging jobs in the area of:
System Software
Web Development
Web Application
Computer Networking
4
BGS College Of Engineering
(Affiliated to Visvesvaraya Technological University, Belagavi)
Bengaluru-86
Department Of Computer Science & Engineering
PROGRAM OUTCOMES
Mission
M1: Enriching students with core knowledge which will avail themselves to resolve real
world problems.
M2: Empowering students by collaborating with industries, motivating them to take up
internships and projects.
M3: Equipping students with the skills making them industry ready, self- employable, &
researchers.
5
BGS College Of Engineering
(Affiliated to Visvesvaraya Technological University, Belagavi)
Bengaluru-86
Department Of Computer Science & Engineering
Mission
M1: Enriching students with core knowledge which will avail themselves to resolve real
world problems.
M2: Empowering students by collaborating with industries, motivating them to take up
internships and projects.
M3: Equipping students with the skills making them industry ready, self- employable, &
researchers.
PEO2: To accomplish higher education and research with highest degree of professionalism and
integrity.
PEO3: To extend the services to mankind by exhibiting leadership qualities and ethical values.
PSO1 Apply the strong knowledge and principles of Computer Science and Engineering to
model and design various computing systems.
PSO2 Develop the diverse applications in well promised domains by adopting the practices
of Computer Science & Engineering.
6
PROGRAM OUTCOMES
PO’s DESCRIPTION
PO1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals,and an engineering specialization to the solution of complex engineering
problems.
PO2 Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering-problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
PO3 Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
PO4 Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of
the information to provide valid conclusions.
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.
PO7 Environment and sustainability: Understand the impact of the professional engineering solutions
in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
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.
PO10 Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.
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 engage in
independent and life-long learning in the broadest context of technological change.
7
BGS College of Engineering
Department of Computer Science and Engineering
FOR
B.E V SEMESTER
Prepared by,
Prof. Vedha C
Assistant Professor,
Dept of CSE.
8
COURSE DETAILS
Course Credit: 1 :
COURSE OUTCOME
CO 1. Design the experiment for the given problem using HTML, Javascript and CSS.
CO 2. Develop the solution for the given real-world problem using jQuery, Ajax and
PHP. CO 3. Analyze the results and produce substantial written documentation..
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 3 2 3 1 2 1 1 1
CO2 3 2 3 1 2 1 1 1
CO3 2 3 1 1 2 1 1
CO2 3 3
CO3 2 1
9
LAB EVALUATION PROCESS
1 Record 5
2 Program Execution 5
TOTAL 10
2 Execution 40
3 Result Verification 20
4 Viva Voce 20
TOTAL 100
Average of internal
2 20
Assessment
TOTAL 50
10
Lab Rubrics
Students’ performance in Laboratory course is evaluated using rubrics defined by the program.
Rubrics for evaluating a lab test in programming lab are displayed in the following
table.
11
Student’s ability in developing programs and testing the program, documenting the work done
through lab record etc are evaluated continuously during all lab sessions.
Sl
Evaluation
Parameters Very Good Good Satisfactory Weak
1 Record and 5 -4 Marks 3 Marks 2 Marks 1 Marks
Observation
Neatly written the Neatly written the Lack of neatness in Data are missing and
[Max. Marks 5] record and regular to record, some data are the record, some data not written record
lab missing in the record. are missing in the neatly and irregular to
Student is regular to record. Student is lab
lab. regular to lab
12
LIST OF PROGRAMS
[Link] Experiments
1 Develop the HTML page named as “[Link]”. Add the following tags with
relevant content.
1. Set the title of the page as “My First Web Page”
2. Within the body use the following tags:
a) Moving text = “Basic HTML Tags”
b) Different heading tags (h1 to h6)
c) Paragraph
d) Horizontal line
e) Line Break
f) Block Quote
g) Pre tag
h) Different Logical Style (<b>, <u>, <sub>, <sup> etc.)
2 Develop the HTML page named as “[Link]” 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.
3 Develop an external style sheet named as “[Link]” 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.
4 Develop HTML page named as “[Link]” having variety of HTML input elements
with background colors, table for alignment & provide font colors & size using CSS styles.
5 Develop HTML page named as “[Link]” having variety of HTML semantic elements
with background colors, text-colors & size for figure, table, aside, section, article, header,
footer... etc.
6 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.
13
7 Develop JavaScript program (with HTML/CSS) for:
a) Converting JSON text to JavaScript Object
b) Convert JSON results into a date
c) Converting From JSON To CSV and CSV to JSON
d) Create hash from string using [Link]() method
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.
9 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.
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.
14
BCSL504| Web Technology Lab
The internet is a global network of interconnected computers and servers that communicate
with each other using standardized protocols (most commonly TCP/IP).
It is a vast infrastructure that allows for the transmission of data across networks worldwide.
● Components:
○ Hardware: Includes servers, routers, switches, cables, and data centers
that facilitate the transmission of data.
○ Protocols: Sets of rules that define how data is transmitted over the
network (e.g., TCP/IP, HTTP, FTP).
○ Connectivity: Encompasses various types of connections, including wired
(Ethernet) and wireless (Wi-Fi, cellular) connections.
● Functionality: The internet allows devices to communicate with each other,
enabling services like email, file sharing, online gaming, and video conferencing.
● Components:
○ Web Pages: Documents that can include text, images, videos, and links to
other documents, typically written in HTML (HyperText Markup Language).
○ Web Browsers: Software applications (like Google Chrome, Firefox, and Safari)
that allow users to access and interact with web pages.
○ Web Servers: Computers that store and serve web content to users over
the internet.
● Functionality: The web enables users to access information, interact with applications,
and engage in social networking, e-commerce, and more through a graphical interface.
Key Differences
Function Facilitates communication and data Provides access to information through web
transfer pages
Protocols Uses various protocols like TCP/IP, Primarily relies on HTTP/HTTPS for
HTTP, FTP communication
Access Requires network connectivity (ISP) Accessed via web browsers over the internet
Front-End Development
● HTML (HyperText Markup Language): The standard markup language used to create
the structure of web pages. HTML elements are the building blocks of web content.
● CSS (Cascading Style Sheets): A stylesheet language used to describe the
presentation of a document written in HTML. CSS controls layout, colors, fonts, and
overall visual design.
● JavaScript: A programming language that enables interactive features on web
pages, such as form validation, animations, and dynamic content updates. JavaScript
frameworks (like React, Angular, and [Link]) are also widely used for building
complex user interfaces.
Back-End Development
Experiment-1
Develop the HTML page named as “[Link]”. Add the following tags
with relevant content.
1. Set the title of the page as “My First Web Page”
2. Within the body use the following tags:
a) Moving text = “Basic HTML Tags”
b) Different heading tags (h1 to h6)
c) Paragraph
d) Horizontal line
e) Line Break
f) Block Quote
g) Pre tag
h) Different Logical Style (<b>, <u>, <sub>, <sup> etc.)
Step-by-Step Instructions:Open a text editor: You can use any text editor like Notepad, Sublime Text,
Visual Studio Code, [Link] a new HTML file: Save it with the name [Link].
Source Code:
<!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>
</body>
</html>
Output:
Experiment-2
Develop the HTML page named as “[Link]” 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 colors.)
c) Provide colour options for rows.
Step-by-Step Instructions:
1. Open a text editor: Use any text editor like Notepad, Sublime Text, Visual Studio Code, etc.
2. Create a new HTML file: Save it with the name [Link].
3. Write the HTML code: Below is the HTML code that includes the table structure, title,
header, footer, row-span, col-span, and color options for cells and rows.
Source Code :
<!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>
</head>
<body>
<h1 style="text-align: center;">Class Time Table</h1>
1. The class attributes (.lab and .elective) apply different colors to specific cells to highlight
lab and elective hours.
2. The colspan attribute merges multiple columns into a single cell for lab hours spanning
two periods.
3. The rowspan attribute merges multiple rows into a single cell for lab hours spanning two rows.
Output :
Experiment- 3
Develop an external style sheet named as “[Link]” 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.
Step-by-Step Instructions:
1. Create the HTML file: Save it as [Link].
2. Create the CSS file: Save it as [Link].
3. Link the CSS file to the HTML file: Use the <link> tag in the <head> section of the HTML file
to link the external stylesheet.
Source Code :
Html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample HTML with External CSS</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<h2>Welcome to My Website</h2>
<p>This paragraph comes right after the heading.</p>
<h3>About Me</h3>
<p>I am a web developer with a passion for creating interactive websites.</p>
<hr>
<div id="special-section">
<h2>Special Section</h2>
<p>This section has a special background and border.</p>
</div>
<div>
<h3>My Projects</h3>
<p class="highlight">Highlighted Project: A Dynamic Web Application.</p>
</body>
</html>
[Link]
a:hover {
/* CSS Selectors */
/* Universal selector */
*{
box-sizing: border-box;
}
ID Selector (#special-section):
1. Targets a specific element with the ID special-section. IDs should be unique on a page.
Output:
Experiment-4
Step-by-Step Instructions:
1. Create the HTML file: Open a text editor and save a new file as [Link].
2. Create the CSS styles: Include CSS styles within the HTML file using the <style> tag to apply
background colors, font colors, and sizes.
Source Code:
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
/* General styles */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
h1 {
text-align:
center; color:
#333333; font-
size: 28px;
margin-bottom: 20px;
}
table {
width: 50%;
margin: 0 auto;
background-color: #ffffff;
th, td {
padding: 10px;
text-align: left;
font-size: 16px;
}
th {
background-color: #4CAF50;
color: white;
font-size: 18px;
}
td {
color: #333333;
}
input[type="radio"], input[type="checkbox"] {
margin-right: 10px;
}
input[type="submit"], input[type="reset"] {
width: 100%;
padding: 10px;
margin-top: 10px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 18px;
input[type="submit"] {
background-color: #4CAF50;
color: white;
}
input[type="submit"]:hover {
background-color: #45a049;
}
input[type="reset"] {
background-color: #f44336;
color: white;
}
input[type="reset"]:hover {
background-color: #e53935;
}
</style>
</head>
<body>
<h1>Registration Form</h1>
</body>
</html>
CSS Styling:
1. Body Styling: Sets the font, background color, text color, and padding for the entire page.
2. Table Styling: Styles the table with width, margin, border collapse, background color,
and shadow.
3. Form Element Styling:
1. input[type="text"], input[type="email"], input[type="password"],
input[type="date"], select: Styles input fields with padding, margin, border, and font
size.
2. Buttons: Styles submit and reset buttons with background color, font size, and
hover effects.
4. Row and Cell Styling: Applies padding, text alignment, and border for table cells
and headers.
5. Class and Element Selectors: Used to style elements based on type and context, ensuring
consistency and readability.
Output:
Experiment-5
Develop HTML page named as “[Link]” having variety of HTML semantic
elements with background colors, text-colors & size for figure, table, aside, section,
article, header, footer... etc.
Step-by-Step Instructions
1. Create the HTML file: Open a text editor and save a new file as [Link].
2. Include CSS styles: Use the <style> tag within the HTML file to define the background colors,
text colors, and sizes for different semantic elements.
Source Code:
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Newspaper Layout</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 20px;
}
nav {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
}
section {
display: flex;
padding: 20px;
}
article {
flex: 3;
background-color: #f4f4f4;
padding: 20px;
margin-right: 20px;
border-radius: 5px;
}
aside {
flex: 1;
background-color: #f0e68c;
padding: 20px;
border-radius: 5px;
}
figure {
text-align: center;
margin: 20px 0;
}
figure img {
max-width: 100%;
height: auto;
border-radius: 5px;
}
figure figcaption {
font-size: 14px;
color: #555;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #333;
color: white;
}
td {
background-color: #fff;
}
footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
position: fixed;
width: 100%;
bottom: 0;
}
</style>
</head>
<body>
<header>
<h1>Daily News</h1>
<p>Your source for the latest news</p>
</header>
<nav>
<section>
<article>
<h2>Main Article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.</p>
<figure>
<img src="[Link] alt="News Image">
<figcaption>Image caption goes here</figcaption>
</figure>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.</p>
<h3>Table of Data</h3>
<table>
<tr>
<th>Category</th>
<th>Details</th>
</tr>
<tr>
<td>World</td>
<td>Global news updates</td>
</tr>
<tr>
<td>Politics</td>
<td>Political insights and analysis</td>
</tr>
<tr>
<td>Technology</td>
<td>Latest tech trends</td>
</tr>
<tr>
<td>Sports</td>
<td>Sports news and scores</td>
</tr>
</table>
</article>
<aside>
<h2>Related Articles</h2>
<ul>
<li><a href="#">Article 1</a></li>
<li><a href="#">Article 2</a></li>
<li><a href="#">Article 3</a></li>
</ul>
</aside>
</section>
<footer>
<p>© 2024 Daily News. All rights reserved.</p>
</footer>
</body>
</html>
Explanation of the HTML and CSS Code
HTML Semantic Elements:
1. <header>: Represents the header section of the page, containing the newspaper title
and tagline.
2. <nav>: Represents the navigation bar with links to different sections of the newspaper.
3. <main>: Contains the main content area, including articles and sidebars.
4. <article>: Represents a self-contained composition in the main content area.
5. <section>: Represents thematic grouping of content within the article.
6. <figure>: Contains an image related to the article content with a caption (<figcaption>).
7. <table>: Used to display top news stories in a tabular format.
8. <aside>: Represents content related to the main content, such as a sidebar with additional
information.
9. <footer>: Represents the footer section of the page, containing copyright information
and contact details.
CSS Styling:
1. Background Colors: Different background colors are used for various sections (header,
nav, main, aside, footer) to differentiate them visually.
2. Text Colors and Sizes: Text color and font size are set for various elements to ensure
readability and visual hierarchy.
3. Element Styling: Specific styles are applied to elements like <figure>, <table>, and <aside>
to enhance their appearance.
4. Flexbox Layout: The main element uses Flexbox to create a two-column layout with the
article and sidebar.
Output:
Experiment-6
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.
Step-by-Step Instructions:
Create an HTML structure: Define the layout of the calculator using HTML.
Apply CSS styles: Style the calculator for a visually appealing and user-friendly interface.
Add JavaScript functionality: Implement the functions that will perform the various calculations.
Source Code:
[Link]
<!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>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content:
center; align-items:
center; height: 100vh;
margin: 0;
}
.calculator {
background-color: #333;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
color: white;
width: 300px;
text-align:
center;
}
.calculator input[type="number"] {
width: 90%;
padding: 10px;
margin-bottom: 10px;
border: none;
border-radius: 5px;
font-size: 18px;
}
.calculator input[type="button"] {
width: 45%;
padding: 10px;
margin: 5px;
border: none;
border-radius: 5px;
font-size: 18px;
cursor: pointer;
background-color: #4CAF50;
color: white;
}
.calculator input[type="button"]:hover
{ background-color: #45a049;
}
.calculator #result {
margin-top: 20px;
font-size: 24px;
color: yellow;
}
</style>
</head>
<body>
<div class="calculator">
<h2>Simple Calculator</h2>
<input type="number" id="num1" placeholder="Enter first number">
<input type="number" id="num2" placeholder="Enter second number (optional)">
<div>
<input type="button" value="Sum" onclick="calculate('sum')">
<input type="button" value="Product" onclick="calculate('product')">
<div id="result"></div>
</div>
<script>
function calculate(operation) {
const num1 =
parseFloat([Link]('num1').value); const num2
= parseFloat([Link]('num2').value); let result =
'';
switch(operation) {
case 'sum':
result = num1 + num2;
break;
case 'product':
result = num1 * num2;
break;
case 'difference':
result = num1 - num2;
break;
case 'remainder':
result = num1 % num2;
break;
case 'quotient':
result = num1 / num2;
break;
case 'power':
result = [Link](num1, num2);
break;
case 'sqrt':
result = [Link](num1);
break;
case 'square':
result = num1 * num1;
break;
default:
CSS Styling:
1. Basic styling is applied to center the calculator on the page and provide padding,
margin, background color, and hover effects.
2. Flexbox is used to align elements and create a responsive layout.
JavaScript Functions:
1. The calculate() function takes an operation parameter to determine which calculation
to perform.
2. It reads the values from the input fields, checks if they are valid numbers, and then
performs the operation.
3. The result is displayed in the result input field.
4. The clearCalculator() function clears the input fields and result field.
Output:
Experiment-7
Source Code:
A)
Step-by-Step Example
1. Create an HTML file named json_to_object.html.
Source Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Convert JSON to JavaScript Object</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f0f0f0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: white;
border-radius: 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
textarea {
width: 100%;
height: 100px;
padding: 10px;
CSS Styling:
1. Basic CSS styling is added to enhance the user interface, making it more visually appealing
and user-friendly.
JavaScript Functionality:
1. convertJsonToObject(): This function reads the JSON text from the textarea and attempts to
parse it into a JavaScript object using [Link]().
2. If parsing is successful, it formats the JavaScript object using [Link]()
with indentation for better readability and displays the output.
3. If an error occurs during parsing (e.g., due to invalid JSON syntax), an error message
is displayed.
Sample input:
{
"name": "Alice",
"age": 28,
Output:
B)
Source Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Convert JSON to Date</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
padding: 20px;
}
#dateDisplay {
<div id="dateDisplay"></div>
<script>
function convertToDate() {
const jsonText = [Link]('jsonDateInput').value;
try {
const jsObject = [Link](jsonText);
const date = new Date([Link]);
[Link]('dateDisplay').innerHTML = `Converted Date: ${[Link]()}`;
} catch (error) {
[Link]('dateDisplay').innerHTML = "Invalid JSON format!";
}
}
</script>
</body>
</html>
Sample input:
{
"date": "2024-08-22T10:00:00Z"
}
C)
Source code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON to CSV and CSV to JSON</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
padding: 20px;
}
#csvJsonDisplay {
margin-top: 20px;
background-color: #333;
color: white;
padding: 10px;
border-radius: 5px;
}
</style>
</head>
<body>
<h3>JSON to CSV</h3>
<textarea id="jsonToCsvInput" rows="10" cols="50" placeholder='Enter JSON array like
[{"name":"John","age":30},{"name":"Jane","age":25}]'></textarea><br><br>
<button onclick="convertJsonToCsv()">Convert to CSV</button>
<h3>CSV to JSON</h3>
<textarea id="csvToJsonInput" rows="10" cols="50" placeholder="Enter CSV text
here..."></textarea><br><br>
<button onclick="convertCsvToJson()">Convert to JSON</button>
<div id="csvJsonDisplay"></div>
<script>
function convertJsonToCsv() {
const jsonText = [Link]('jsonToCsvInput').value;
try {
const jsObject = [Link](jsonText);
const headers = [Link](jsObject[0]);
const csv = [
[Link](','),
...[Link](row => [Link](header => row[header]).join(','))
].join('\n');
[Link]('csvJsonDisplay').innerHTML = `<pre>${csv}</pre>`;
} catch (error) {
[Link]('csvJsonDisplay').innerHTML = "Invalid JSON format!";
}
}
function convertCsvToJson() {
const csvText = [Link]('csvToJsonInput').value;
try {
const [headers, ...rows] = [Link]('\n');
const headerArray = [Link](',');
const jsonArray = [Link](row => {
const values = [Link](',');
return [Link]((obj, header, index) => {
obj[header] = values[index];
return obj;
}, {});
});
</body>
</html>
Sample input:
Sample Input for JSON to CSV
[
{"name": "John Doe", "age": 30, "city": "New York"},
{"name": "Jane Doe", "age": 25, "city": "Los Angeles"}
]
name,age,city
John Doe,30,New York
Jane Doe,25,Los Angeles
Output:
D)
Source Code:
// Import the crypto module
const crypto = require('crypto');
return hashOutput;
}
Sample input:
const input = 'Hello, World!';
Creating a Hash:
1. The createHash function from the crypto module is used to create a new hash object. The
algorithm for hashing is specified ('sha256' in this example, but you can use others like 'md5',
'sha512', etc.).
Experiment-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.
Source Code:
Source Code:
A)
Explanation:
PHP Session/Counter: We'll use a text file to store the number of visitors. Each time the page loads,
the PHP script reads this file, increments the count, and updates the file.
HTML/CSS: The visitor count is displayed on the page, and we'll use CSS to style the content with
relevant headings.
Step-by-Step Code:
1. PHP Code to Track and Display Visitor Count
<?php
$counterFile = "[Link]";
if (!file_exists($counterFile)) {
file_put_contents($counterFile, "0");
}
$currentCount = file_get_contents($counterFile);
$newCount = $currentCount + 1;
file_put_contents($counterFile, $newCount);
?>
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
.container {
background: #fff;
padding: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0,
0.1); border-radius: 8px;
margin: 0 auto;
width: 60%;
}
h1 {
font-size: 2.5em;
margin: 0;
}
p{
font-size: 1.2em;
color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to Our Website!</h1>
<p>You are visitor number: <strong><?php echo $newCount; ?></strong></p>
</div>
</body>
</html>
1. Centered Design:
The page is centered vertically and horizontally using Flexbox (display: flex;, justify-content: center;, and
align-items: center), providing a balanced layout on any screen size.
2. Container Styling:
The .container class creates a white box with padding and a subtle box shadow for a modern, clean look. The
width is set to 60% for a responsive layout.
3. Text Styling:
The heading (h1) and paragraph (p) are styled for readability, with the heading size (2.5em) making the title
stand out and the visitor count displayed in bold using <strong>.
OUTPUT:
B)
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "students";
$students = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$students[] = $row;
}
}
$temp = $arr[$i];
$arr[$i] = $arr[$minIndex];
$arr[$minIndex] = $temp;
}
}
selectionSort($students, 'name');
?>
HTML:
<!DOCTYPE html>
<head>
<title>Sorted Student Records | vtucode</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f0f2f5;
h2 {
text-align: center;
color: #4A90E2;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
background-color: #fff;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
margin: 0 auto;
}
th,
td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #4A90E2;
color: white;
text-transform: uppercase;
letter-spacing: 0.03em;
}
tr {
transition: background-color 0.3s ease;
}
tr:hover {
background-color: #f1f1f1;
}
table,
th,
td {
display: block;
width: 100%;
}
th,
td {
box-sizing: border-box;
}
tr {
margin-bottom: 15px;
display: block;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
th {
position: absolute;
top: -9999px;
left: -9999px;
}
td {
border: none;
position: relative;
padding-left: 50%;
text-align: right;
}
td:before {
content: attr(data-label);
position: absolute;
left: 0;
width: 50%;
<body>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>USN</th>
<th>Branch</th>
<th>Email</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<?php foreach ($students as $student): ?>
<tr>
<td data-label="ID"><?php echo htmlspecialchars($student['id']); ?></td>
<td data-label="Name"><?php echo htmlspecialchars($student['name']); ?></td>
<td data-label="USN"><?php echo htmlspecialchars($student['usn']); ?></td>
<td data-label="Branch"><?php echo htmlspecialchars($student['branch']); ?></td>
<td data-label="Email"><?php echo htmlspecialchars($student['email']); ?></td>
<td data-label="Address"><?php echo htmlspecialchars($student['address']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
Explanation:
1. Database Connection:
The script connects to a MySQL database using the mysqli object. The database details
(servername, username, password, dbname) are provided to create the connection.
A SQL query (SELECT * FROM students) retrieves all student records from the students
table.
2. Data Retrieval:
The results of the query are stored in the $students array, where each element represents a
student record (an associative array of student attributes like name, usn, branch, etc.).
3. Selection Sort:
The selectionSort function is used to sort the $students array based on the name field.
The sorting is done by comparing the name field of each student and rearranging the array
using selection sort logic.
4. HTML Table:
The sorted student records are displayed in an HTML table. Each record is represented as a
row, and the table includes columns for ID, Name, USN, Branch, Email, and Address.
5. CSS Styling:
The page is styled with CSS, including responsive design for smaller screens using media
queries. On smaller screens, the table layout becomes more readable by displaying each
record as a block with labels.
OUTPUT:
Experiment-9
Source Code:
A)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Append Example</title>
<style>
body {
font-family: Arial, sans-serif;
}
#content {
margin-top: 20px;
padding: 10px;
background-color:
#e0f7fa; border-radius:
5px;
}
</style>
<script src="[Link]
</head>
<body>
<h1>jQuery Append Content Example</h1>
<p id="paragraph">This is an existing paragraph.</p>
<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<button id="appendContent">Append Content</button>
<script>
$(document).ready(function() {
$('#appendContent').click(function() {
$('#paragraph').append(' Appended text.');
$('#list').append('<li>New Item</li>');
Output:
<script>
$('#animateElement').click(function() {
$('#animateDiv').animate({
width: '200px',
height: '200px',
opacity: 0.5
}, 1000);
});
</script>
Output:
<script>
$('#changeColor').click(function() {
$('#animateDiv').animate({ backgroundColor: 'blue' }, 1000);
});
</script>
Output:
Final Output:
Experiment-10
Source Code:
A)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vanilla JS AJAX Example</title>
<style>
body {
font-family: Arial, sans-serif;
}
#content {
margin-top: 20px;
padding: 10px;
background-color: #f4f4f4;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>Load Content from a File with AJAX (Vanilla JS)</h1>
<button id="loadContent">Load Content</button>
<div id="content"></div>
<script>
[Link]('loadContent').addEventListener('click', function() {
var xhr = new XMLHttpRequest();
[Link] = function() {
if ([Link] == 200) {
[Link]('content').innerHTML = [Link];
}
};
[Link]();
});
</script>
</body>
</html>
Output:
B)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery AJAX Example</title>
<style>
body {
font-family: Arial, sans-serif;
}
#content {
margin-top: 20px;
padding: 10px;
background-color:
#e0f7fa; border-radius:
5px;
}
</style>
<script src="[Link]
</head>
<body>
<h1>Load Content from a File with AJAX (jQuery)</h1>
<button id="loadContent">Load Content</button>
<div id="content"></div>
Output:
C)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery getJSON Example</title>
<style>
body {
font-family: Arial, sans-serif;
}
#content {
margin-top: 20px;
padding: 10px;
background-color: #f0f4c3;
border-radius: 5px;
}
</style>
<script src="[Link]
</head>
<body>
<h1>Load JSON Data with getJSON()</h1>
<script>
$('#loadContent').on('click', function() {
$.getJSON('[Link]', function(data) {
var output = '<h2>' + [Link] + '</h2>';
output += '<p>' + [Link] + '</p>';
$('#content').html(output);
});
});
</script>
</body>
</html>
[Link]
{
"title": "JSON Example",
"description": "This is an example of loading JSON data using jQuery's getJSON() method."
}
Output:
D)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>parseJSON Example</title>
<style>
body {
font-family: Arial, sans-serif;
}
#content {
margin-top: 20px;
padding: 10px;
background-color: #f3e5f5;
border-radius: 5px;
}
<script>
$('#loadContent').on('click', function() {
var jsonString = '{"name": "John Doe", "age": 30, "city": "New
York"}'; var parsedData = $.parseJSON(jsonString);
Output:
Viva Questions
1. What is the purpose of the <title> tag in an HTML document?
The <title> tag defines the title of the HTML document, displayed in the browser’s title bar or tab.
It’s also used by search engines and when the page is bookmarked.
2. How does the <marquee> tag function, and what are its alternatives?
The <marquee> tag creates scrolling text or images. It's deprecated in HTML5 due to accessibility
issues. Alternatives include using CSS animations or JavaScript to achieve similar effects.
6. Why is the <pre> tag used, and how does it differ from the <p> tag?
The <pre> tag preserves whitespace, line breaks, and formatting as typed in the HTML document. It
differs from the <p> tag, which collapses multiple spaces into a single space and doesn’t preserve
line breaks.
7. What are logical styles in HTML, and how do they enhance the presentation of text?
Logical styles (e.g., <em>, <strong>) apply both stylistic formatting and semantic meaning. They
help search engines and assistive technologies interpret the document structure and content more
effectively.
10. Explain the significance of table headers (<thead>) and footers (<tfoot>) in an HTML table.
<thead> defines the table's header section, typically used to label columns. <tfoot> defines the footer
section, useful for summary rows or additional notes. These sections help organize data and improve
table readability.
11. What is the difference between an ID selector and a class selector in CSS?
● An ID selector (#id) is unique and used for styling a single element. Each element can
only have one ID, and an ID can only be used once per page.
● A class selector (.class) can be applied to multiple elements, allowing for reusable
styles across different parts of the webpage.
12. How does the element selector work, and when is it most appropriate to use it?
The element selector (e.g., p, h1) targets all instances of a particular HTML element. It’s most
appropriate when you want to style every occurrence of a tag globally, like setting a universal font
for all paragraphs (p).
13. Can you explain the significance of using an external stylesheet instead of inline or
internal CSS?
An external stylesheet keeps CSS separate from HTML, promoting a cleaner, more
maintainable structure. It allows for reuse across multiple HTML files and makes updating
styles across a site easier, rather than embedding CSS in each document.
14. What is a group selector in CSS, and how does it help in reducing redundancy?
A group selector (e.g., h1, h2, p) applies the same styles to multiple elements, reducing redundancy
in the code. Instead of repeating the same styles for each tag, grouping them makes the code more
efficient and concise.
15. Explain how attribute selectors work and provide a practical example of their use.
Attribute selectors target elements based on attributes and their values. For example, [type="text"]
selects input fields of type text:
EX: input[type="text"] { background-color: #f0f0f0; }
This applies styles only to specific input fields with the type="text" attribute.
16. How does the hover pseudo-class enhance the interactivity of links on a webpage?
The :hover pseudo-class enhances the interactivity of links by changing styles (like colour,
background, etc.) when a user hovers over them. It’s commonly used to indicate clickable elements
and improve user experience:
Ex: a:hover { text-decoration: underline; color: blue; }
17. What are the advantages of using CSS to style HTML elements compared to inline styling?
CSS allows for separation of concerns (style from content), easier maintainability, and reuse across
multiple elements or pages. It avoids inline clutter and provides flexibility through stylesheets,
making it easier to update and manage designs globally.
18. How do you decide when to use an ID selector over a class selector?
Use an ID selector when styling a unique element on the page (e.g., a header, a specific section). Use
a class selector for reusable styles across multiple elements (e.g., button styles, card designs).
input[type="text"] accepts any text input, while input[type="email"] is designed to validate and
accept email addresses.
Font size ensures the readability of form elements. Proper sizing enhances user experience, making
the form easier to fill out.
The placeholder provides a hint inside the input field to guide the user on what type of information is
expected (e.g., "Enter first name").
22. What is the purpose of using semantic elements like <header>, <article>, and <aside>?
Semantic elements define the structure and meaning of the content, making it more accessible for
search engines and assistive technologies.
The <figure> tag is used to encapsulate images, and <figcaption> provides a caption, making it easier
to describe images or visual elements.
The <aside> tag holds content related to the main content, such as advertisements or additional
information.
parseFloat converts the input value (which is a string) into a floating-point number for mathematical
operations.
The program checks if the second number is zero before dividing and returns the message
"Cannot divide by zero" to avoid mathematical errors.
28. How does the square root function work in this calculator?
It uses JavaScript's [Link]() function to compute the square root of the first number.
29. Why are background and font colors applied in CSS rather than directly in HTML?
CSS separates content from design, making it easier to manage styles and ensuring the HTML
structure focuses on content.
[Link](num1, num2) returns the value of num1 raised to the power of num2.
31. What is the advantage of using switch-case instead of multiple if-else statements in this
calculator?
switch-case is more readable and efficient when there are multiple distinct conditions like this,
compared to chaining several if-else statements.
The file_exists() function is used to check if a file exists on the server before attempting to read or
write to it. This helps to prevent errors when trying to access non-existent files.
file_get_contents() reads the entire content of a file into a [Link] example it is used to retrieve the
current visitor count from [Link].
file_put_contents() writes data to a file. It can either create a file if it doesn’t exist or overwrite the
contents of an existing file. In this program, it updates the visitor count in [Link].
In PHP, you can increment a numeric value using the ++ operator. For example, $current_count++
increases the value of $current_count by 1.
The .txt file ([Link]) is used to store the current number of visitors. It serves as persistent storage
that PHP reads from and writes to, ensuring the visitor count is maintained between sessions.
36. How does PHP handle multiple users visiting the page simultaneously?
PHP handles multiple users by executing code on the server for each request independently. However,
in the case of file handling (like updating [Link]), race conditions may occur. Using file locking
mechanisms or switching to database storage can prevent such issues.
37. What are the security concerns when writing to a file in PHP?
○ File permission issues: Incorrect permissions could allow unauthorized users to modify files.
○ Race conditions: As mentioned, simultaneous access could corrupt data.
○ Injection attacks: If user input is involved in file operations, it could lead to injection attacks
like path traversal, which must be guarded against using proper validation.
38. Explain how you can handle click events in jQuery.
Answer: Click events in jQuery can be handled using the .click() method or the .on('click',
function() {}) method. These methods bind a function to the click event of a selected element,
allowing for interactive user experiences.
Answer: The $(document).ready() function ensures that the DOM is fully loaded before
executing any jQuery code. It helps prevent errors by ensuring that the elements are available
for manipulation when the script runs.
Answer: AJAX (Asynchronous JavaScript and XML) is a technique used to send and receive
data asynchronously without refreshing the entire web page. It works by using the
XMLHttpRequest object or modern fetch API to send requests to the server, which then returns
data (often in JSON format) that can be processed and displayed dynamically.
41. Explain the difference between the XMLHttpRequest and the fetch API.
Answer: XMLHttpRequest is an older API for making AJAX requests, while the fetch API is a
modern alternative that is more powerful and flexible. fetch returns a Promise, making it easier to
work with asynchronous code. Additionally, fetch supports more features, such as easier handling of
response types.
Answer: Errors in AJAX requests can be handled using the error callback in jQuery's $.ajax()
method or by using .catch() when working with Promises in the fetch API. It's essential to check the
response status to determine if the request was successful.
Answer: getJSON() is a shorthand method for making a GET request to fetch JSON data from a
URL and automatically parses the response. parseJSON(), on the other hand, is used to convert a
JSON string into a JavaScript object and is typically used when you have JSON data in string
format.
Answer: The async property determines whether the request is asynchronous or synchronous. When
set to true (default), it allows the browser to continue processing other scripts while waiting for the
response. If set to false, the browser will wait for the request to complete before continuing.
45. What happens if an AJAX request is made to a URL that does not exist?
Answer: If an AJAX request is made to a non-existent URL, the server will typically respond with a
404 Not Found status. In the error callback or .catch() block, you can handle this response and inform
the user that the requested resource is not available.
46. What is the difference between the fadeIn() and animate() methods?
Answer: The fadeIn() method specifically fades an element into view by changing its opacity, while
the animate() method can change any CSS properties, including size, position, and color, providing
more flexibility in animations.