Web Technology Lab BCSL504 Manual 2024-25-1
Web Technology Lab BCSL504 Manual 2024-25-1
LABORATORY MANUAL
SUBJECT: WEB TECHNOLOGY LAB
SUBJECT CODE: BCSl504
SEMESTER: V
Outcome Based Education (OBE) and Choice Based Credit System (CBCS)
(Effective from the academic year 2022-23)
Objectives
Vision
Mission.
To keep pace with advancements in knowledge and make the students competitive
and capable at the global level.
To create an environment for the students to acquire the right physical,
intellectual, emotional and moral foundations and shine as torch bearers of
tomorrow's society.
To strive to attain ever-higher benchmarks of educational excellence.
Department of Computer Science & Engineering
Vision of the Department
1. Empower students with a strong basis in the mathematical, scientific and engineering
fundamentals to solve computational problems and to prepare them for employment, higher
learning and R&D.
2. Gain technical knowledge, skills and awareness of current technologies of computer
science engineering and to develop an ability to design and provide novel engineering
solutions for software/hardware problems through entrepreneurial skills.
3. Exposure to emerging technologies and work in teams on interdisciplinary projects with
effective communication skills and leadership qualities.
4. Ability to function ethically and responsibly in a rapidly changing environment by
Applying innovative ideas in the latest technology, to become effective professionals in
Computer Science to bear a life-long career in related areas.
1. Ability to apply skills in the field of algorithms, database design, web design, cloud
computing and data analytics.
2. Apply knowledge in the field of computer networks for building network and internet based
applications.
Web Technology Lab Semester 5
Course Code BCSL504 CIE Marks 50
Teaching Hours/Week (L:T:P: S) 0:0:2:0 SEE Marks 50
Credits 01 Exam Hours 100
Examination type (SEE) Practical
Course objectives:
List of Experiments:
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.
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.
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.
Construct a Website (multiple Web pages) containing „Resume‟ and Bio -data by using
relevant HTML elements and appropriate styling for presentation with
CSS/jQuery/JavaScript. Host the Website on a cloud platform.
Build a Web application with HTML, CSS, JavaScript, jQuery and PHP for online
application/registration form. Form should accept the information and print/display on a
browser with formatting/styling upon submission (Button click) on success. Host the
application on a cloud platform.
Course outcomes (Course Skill Set):
At the end of the course, the student will be able to:
Design the experiment for the given problem using HTML, Javascript and CSS.
Develop the solution for the given real-world problem using jQuery, Ajax and
PHP.
Analyze the results and produce substantial written documentation.
The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End
Exam (SEE) is 50%. The minimum passing mark for the CIE is 40% of the maximum
marks (20 marks out of 50) and for the SEE minimum passing mark is 35% of the
maximum marks (18 out of 50 marks). A student shall be deemed to have satisfied the
academic requirements and earned the credits allotted to each subject/ course if the
student secures a minimum of 40% (40 marks out of 100) in the sum total of the CIE
(Continuous Internal Evaluation) and SEE (Semester End Examination) taken together
The Sum of scaled-down marks scored in the report write-up/journal and marks of a
test is the total CIE marks scored by the student.
Semester End Evaluation (SEE):
General rubrics suggested for SEE are mentioned here, writeup-20%, Conduction
procedure and result in -60%, Viva-voce 20% of maximum marks. SEE for practical shall
be evaluated for 100 marks and scored marks shall be scaled down to 50 marks (however,
based on course type, rubrics shall be decided by the examiners)
Change of experiment is allowed only once and 15% of Marks allotted to the procedure
part are to be made zero.
The minimum duration of SEE is 02 hours
Books:
1. Randy Connolly and Ricardo Hoar, Fundamentals of Web Development, 3rd
edition, Pearson, 2021
2. Robert W Sebesta, Programming the World Wide Web, 8th Edition, Pearson
Education, 2020.
Web Links:
https://www.w3schools.com/html/default.asp
https://www.w3schools.com/css/default.asp
https://www.w3schools.com/js/js_examples.asp
https://www.geeksforgeeks.org/javascript-examples/
https://www.w3schools.com/php/default.asp
https://www.w3schools.com/jquery/default.asp
https://www.w3schools.com/js/js_ajax_intro.asp
https://www.geeksforgeeks.org/jquery-tutorial/
CONTENTS
1 INTRODUCTION 1
Program 1
Develop the HTML page named as “Myfirstwebpage.html”. 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)
2 30
c) Paragraph
d) Horizontal line
e) Line Break
f) Block Quote
g) Pre tag
Different Logical Style (b>, <u>, <sub>, <sup> etc.)
Program 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
3 footer, row-span and col-span etc. 33
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 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
4 37
different CSS selectors for tags and demonstrate the significance of
each.
Program 4
Develop HTML page named as “registration.html” having variety of
5 HTML input elements with background colors, table for alignment & 41
provide font colors & size using CSS styles.
Program 5
Develop HTML page named as “newpaper.html” having variety of
6 HTML semantic elements with background colors, text-colors & size 45
for figure, table, aside, section, article, header, footer… etc.
Program 6
Apply HTML, CSS and JavaScript to design a simple calculator to
7 perform the following operations: sum, product, difference, 50
remainder, quotient, power, square-root and square.
Program 7
Develop JavaScript program (with HTML/CSS) for:
a) Converting JSON text to JavaScript Object
8 b) Convert JSON results into a date 55
c) Converting From JSON To CSV and CSV to JSON
d) Create hash from string using crypto.createHash() method
Program 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
9 visitors, with relevant headings. 60
b. Develop a PHP program (with HTML/CSS) to sort the student
records which are stored in the database using selection sort.
Program 9
Develop jQuery script (with HTML/CSS) for:
a) Appends the content at the end of the existing paragraph and
list.
10 67
b) Change the state of the element with CSS style using animate()
method
c) Change the color of any div that is animated.
Program 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.
11 b) Use ajax() method (with Jquery) to add the text content from the 70
text file by sending ajax request.
c) Illustrate the use of getJSON() method in jQuery
Illustrate the use of parseJSON() method to display JSON values.
Introduction to HTML
1. What is HTML?
HTML stands for HyperText Markup Language. It is the standard language used to create
and design web pages. HTML structures content on the web, allowing browsers to interpret
and display text, images, and other resources.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph.</p>
</body>
</html>
<!DOCTYPE html>: Declares the document type and HTML version (HTML5 in this
case).
<html>: Root element that contains all other HTML elements.
<head>: Contains meta-information about the document, such as the title and
character set.
<body>: Contains the content of the web page, such as headings, paragraphs, images,
and links.
HTML is made up of elements, which are defined by tags. Tags are enclosed in angle
brackets, e.g., <tagname>. Elements can have attributes to provide additional information.
For example:
Headings: <h1> to <h6> elements define headings, where <h1> is the largest and <h6>
is the smallest.
<h1>Main Heading</h1>
<h2>Subheading</h2>
<p>This is a paragraph.</p>
3. Images
1. Lists
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
<ul>
<li>Item one</li>
<li>Item two</li>
</ul>
2. Tables
Table Structure: Tables are created using <table>, with rows defined by <tr>,
headers by <th>, and cells by <td>.
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
1. Attributes
Attributes provide additional information about elements. They are placed in the opening tag
of an element and usually come in name-value pairs.
<a href="https://example.com">Link</a>
2. Forms
Forms allow users to submit data to a server. Common form elements include:
1. HTML5 Elements
HTML5 introduces new semantic elements that make it easier to structure content:
Semantic Elements:
o <header>: Defines a header for a document or section.
o <footer>: Defines a footer for a document or section.
o <article>: Represents a self-contained piece of content.
o <section>: Defines sections within a document.
<header>
<h1>Page Header</h1>
</header>
<section>
<article>
<h2>Article Title</h2>
<p>Article content goes here.</p>
</article>
</section>
<footer>
<p>Footer content</p>
</footer>
2. Multimedia Elements
<audio controls>
<source src="audio.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
3. Best Practices
Introduction to CSS
1. What is CSS?
CSS stands for Cascading Style Sheets. It is used to style and layout web pages. CSS allows
you to separate content (HTML) from design (styles), making it easier to maintain and update
the appearance of a website.
Example:
selector {
property: value;
}
body {
background-color: lightblue;
}
h1 {
color: navy;
text-align: center;
}
Internal CSS: Defined within the <style> tag inside the <head> section of the
HTML document.
<style>
p {
color: red;
}
</style>
External CSS: Linked to an HTML document via the <link> tag. This is the most
recommended approach for larger sites.
1. Selectors
Selectors are used to target HTML elements you want to style. Here are some common types:
p {
color: green;
}
Class Selector: Targets elements with a specific class attribute. Prefixed with a dot
(.).
.class-name {
font-size: 18px;
}
ID Selector: Targets an element with a specific id attribute. Prefixed with a hash #.
#unique-id {
background-color: yellow;
}
Attribute Selector: Targets elements based on an attribute or its value.
input[type="text"] {
border: 1px solid black;
}
Universal Selector: Targets all elements on the page.
* {
margin: 0;
padding: 0;
}
2. Combining Selectors
CSS Properties
1. Text Properties
img {
width: 100px;
height: auto;
}
3. Background Properties
body {
background-color: lightgray;
}
div {
background-image: url('background.jpg');
}
div {
background-size: cover;
}
1. Responsive Design
Responsive design ensures that your website looks good on all devices and screen sizes.
Flexible Grid Layouts: Use percentages and flexible units like vw (viewport width)
and vh (viewport height).
.container {
width: 80%;
margin: 0 auto;
}
2. Flexbox
Flexbox is a layout model that allows for more efficient and flexible layouts.
.container {
display: flex;
justify-content: space-between;
}
Flex Properties:
o display: flex;: Defines a flex container.
o flex-direction: Defines the direction of flex items.
.container {
flex-direction: row; /* or column */
}
.container {
justify-content: center;
}
3. Grid Layout
.grid-container {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 10px;
}
.grid-item {
background-color: lightblue;
padding: 20px;
}
Grid Properties:
o grid-template-columns: Defines the columns of the grid.
o grid-template-rows: Defines the rows of the grid.
1. Best Practices
/* Layout Styles */
.container { ... }
/* Typography Styles */
h1 { ... }
Minimize Use of Inline Styles: Use external or internal CSS for better
maintainability.
Optimize Performance: Minify CSS files and combine multiple stylesheets where
possible.
Use Browser Developer Tools: Inspect and debug styles in real-time.
2. CSS Preprocessors
Sass: A CSS preprocessor that adds features like variables, nesting, and mixins.
$primary-color: #333;
body {
color: $primary-color;
}
@primary-color: #333;
body {
color: @primary-color;
}
3. CSS Frameworks
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstra
p.min.css">
Tailwind CSS: A utility-first CSS framework that allows for highly customizable
styling.
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.mi
n.css" rel="stylesheet">
4. Resources
MDN Web Docs: Comprehensive resource for CSS documentation and examples.
CSS-Tricks: Tutorials and tips for CSS development.
Can I use: Check browser support for CSS features
Introduction to JavaScript
1. What is JavaScript?
JavaScript is a versatile, high-level programming language that is widely used for creating
interactive and dynamic web content. It is an essential part of web development, along with
HTML and CSS.
Inline JavaScript: Directly within an HTML element using the onclick attribute.
Internal JavaScript: Inside the <script> tag within the HTML <head> or <body>
section.
<script>
console.log('Hello World!');
</script>
External JavaScript: In a separate .js file linked via the <script> tag.
<script src="script.js"></script>
3. Basic Syntax
Comments: Used to annotate the code and are ignored by the interpreter.
o Single-line comment: // This is a comment
o Multi-line comment: /* This is a multi-line comment */
Variables: Declared using var, let, or const.
Data Types:
o String: Text ("Hello", 'World')
o Number: Numeric values (42, 3.14)
o Boolean: True or false (true, false)
o Object: Collection of key-value pairs
o Array: Ordered list of values ([1, 2, 3])
1. Operators
switch (day) {
case 1:
console.log('Monday');
break;
case 2:
console.log('Tuesday');
break;
default:
console.log('Weekend');
}
Loops: Repeats code multiple times.
// For loop
for (let i = 0; i < 5; i++) {
console.log(i);
}
// While loop
let count = 0;
while (count < 5) {
console.log(count);
count++;
}
// Do-While loop
let num = 0;
do {
console.log(num);
num++;
} while (num < 5);
1. Functions
Function Declaration:
function greet(name) {
return 'Hello, ' + name;
}
console.log(square(4)); // Output: 16
2. Scope
function example() {
let localVar = 'Local';
console.log(localVar); // Accessible here
}
console.log(localVar); // Error: localVar is not defined
Block Scope: Variables declared with let or const within a block (e.g., if or for).
if (true) {
let blockVar = 'Block';
console.log(blockVar); // Accessible here
}
console.log(blockVar); // Error: blockVar is not defined
1. Objects
Creating an Object:
let person = {
name: 'John',
age: 30,
greet: function() {
return 'Hello, ' + this.name;
}
};
2. Arrays
Creating an Array:
console.log(numbers[0]); // Output: 1
Array Methods:
1. DOM Manipulation
JavaScript interacts with the Document Object Model (DOM) to modify web page content
and structure.
Selecting Elements:
Modifying Content:
Event Handling:
element.addEventListener('click', () => {
alert('Element clicked!');
});
2. Asynchronous JavaScript
Handle operations that take time (e.g., network requests) without blocking the main thread.
Callbacks:
function fetchData(callback) {
setTimeout(() => {
callback('Data');
}, 1000);
}
fetchData();
3. Error Handling
try {
let result = riskyOperation();
} catch (error) {
console.log('An error occurred:', error);
}
4. Best Practices
Write Clean and Readable Code: Use meaningful variable names and maintain
consistent formatting.
Follow the DRY Principle: Don’t Repeat Yourself. Use functions and objects to
avoid code duplication.
Use Strict Mode: Enforce stricter parsing and error handling.
'use strict';
Test and Debug: Regularly test and debug code to ensure functionality and
performance.
AJAX is a technique used in web development to create interactive and dynamic web
applications. It allows web pages to be updated asynchronously by exchanging small amounts
of data with the server behind the scenes. This enables a web page to update without
requiring a full page reload, enhancing the user experience.
1. Understanding AJAX
1.1 What is AJAX? AJAX stands for Asynchronous JavaScript and XML. It’s not a
programming language but a set of web development techniques combining JavaScript and
XML (or JSON). The key idea is to allow web applications to send and receive data from a
server asynchronously without disrupting the current page.
XMLHttpRequest Object: The core JavaScript object used to send requests and
receive responses.
JavaScript: Used to handle the request and update the page.
Server-Side Script: Typically written in languages like PHP, Python, or Node.js,
responsible for processing requests.
2. Implementing AJAX
Here’s a basic example of how to use XMLHttpRequest to fetch data from a server.
Example Code:
console.log(response);
// Update the page with the response
document.getElementById('output').textContent = response.message;
} else {
// Request failed
console.error('Request failed with status:', xhr.status);
}
};
The fetch API is a more modern alternative to XMLHttpRequest, providing a simpler and
more flexible approach for handling network requests.
Example Code:
While XML was traditionally used with AJAX, JSON is now the more common format for
data interchange.
XML Example:
JSON Example:
document.getElementById('output').textContent =
jsonResponse.message;
};
xhr.onerror = function() {
console.error('Request failed');
};
fetch('https://api.example.com/data')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.catch(error => {
console.error('There was a problem with the fetch
operation:', error);
});
3.1 Dynamic Content Loading AJAX is commonly used to dynamically load content
without refreshing the entire page, such as in infinite scrolling or live search features.
3.2 Form Submission Submit forms asynchronously to update parts of a web page or
provide real-time feedback without refreshing.
3.3 Real-Time Updates Use AJAX for real-time applications like chat applications, live
notifications, and stock price updates.
3.4 Enhancing User Experience AJAX can be used to improve the user experience by
providing faster interactions and reducing wait times for content updates.
4.1 Summary
AJAX is a powerful technique that, when used effectively, can greatly enhance the
responsiveness and interactivity of web applications.
jQuery
jQuery is a fast, lightweight, and feature-rich JavaScript library designed to simplify HTML
document traversal, event handling, and animation. It provides a more straightforward syntax
for common JavaScript tasks and makes it easier to work with the DOM (Document Object
Model), events, and AJAX.
1. Introduction to jQuery
1.1 What is jQuery? jQuery is a cross-browser JavaScript library that simplifies HTML
document manipulation, event handling, and animation. It allows developers to write less
code to accomplish common tasks, improving productivity and code readability.
Simplified Syntax: Provides a more concise syntax for common JavaScript tasks.
Cross-Browser Compatibility: Handles inconsistencies across different browsers.
Plugins: Offers a vast number of plugins to extend its functionality.
1.3 Including jQuery in Your Project You can include jQuery in your project either by
downloading it or using a Content Delivery Network (CDN).
Using a CDN:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
Downloading jQuery: Download from the official website and include it in your
project directory.
<script src="path/to/jquery.min.js"></script>
Selecting by ID:
Selecting by Class:
Selecting by Tag:
Changing Content:
Modifying Attributes:
Adding/Removing Classes:
Click Event:
$('#myButton').click(function() {
alert('Button clicked!');
});
Hover Event:
$('#myElement').hover(
function() { $(this).addClass('hover'); }, // Mouse enter
function() { $(this).removeClass('hover'); } // Mouse leave
);
2.4 Animations
Show/Hide Elements:
Fading In/Out:
Sliding Up/Down:
GET Request:
$.get('https://api.example.com/data', function(data) {
console.log(data);
});
POST Request:
$.ajax({
url: 'https://api.example.com/data',
method: 'GET',
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.error('Error:', error);
}
});
$.getJSON('https://api.example.com/data', function(data) {
console.log(data);
});
jQuery’s extensibility is enhanced through plugins. Plugins are reusable pieces of code that
extend jQuery’s functionality. Examples include:
Use $() Selectors Wisely: Minimize the number of selectors to improve performance.
Avoid Global Namespace Pollution: Use IIFE (Immediately Invoked Function
Expressions) to encapsulate code.
Use Modern Alternatives: Consider using vanilla JavaScript or modern
libraries/frameworks if jQuery's features are no longer necessary.
If transitioning to a framework like React or Vue, consider gradually migrating from jQuery
to avoid rewriting code.
PHP is a widely-used open-source scripting language designed for web development but is
also used as a general-purpose language. It enables the creation of dynamic and interactive
web applications and is often embedded within HTML.
1. Introduction to PHP
1.1 What is PHP? PHP stands for Hypertext Preprocessor. It is a server-side scripting
language designed primarily for web development but also used as a general-purpose
language. PHP scripts are executed on the server, and the result is sent to the client’s browser
as plain HTML.
Server-Side Execution: PHP code is executed on the server, generating HTML that
is sent to the client.
Embedded in HTML: PHP code can be embedded directly within HTML code.
Database Interaction: PHP has built-in support for interacting with various
databases, especially MySQL.
Cross-Platform: Runs on multiple operating systems, including Windows, Linux,
and macOS.
2.1 PHP Tags: PHP code is enclosed within <?php and ?> tags.
Example:
<?php
echo "Hello, World!";
?>
2.2 Variables:
Declaring Variables: Variables in PHP start with a dollar sign $ and do not require
explicit type declaration.
Variable Types:
o String: "Hello"
o Integer: 42
o Float: 3.14
o Boolean: true, false
o Array: array(1, 2, 3)
o Object: Instances of classes
o NULL: Represents a variable with no value.
2.3 Concatenation:
2.4 Comments:
3. Control Structures
If Statement:
Switch Statement:
switch ($day) {
case 1:
echo "Monday";
break;
case 2:
echo "Tuesday";
break;
default:
echo "Weekend";
}
3.2 Loops:
For Loop:
While Loop:
$count = 0;
while ($count < 5) {
echo $count;
$count++;
}
Do-While Loop:
$num = 0;
do {
echo $num;
$num++;
} while ($num < 5);
4. Functions
function greet($name) {
return "Hello, " . $name;
}
Default Parameters:
function multiply($a, $b = 2) {
return $a * $b;
}
Variable-Length Arguments:
function sum(...$numbers) {
return array_sum($numbers);
}
5. Arrays
$matrix = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9)
);
echo $matrix[1][2]; // Output: 6
GET Method:
// form.php
<?php
$username = $_GET['username'];
echo "Username: " . htmlspecialchars($username);
?>
POST Method:
// form.php
<?php
$username = $_POST['username'];
echo "Username: " . htmlspecialchars($username);
?>
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
if (empty($username)) {
echo "Username is required";
} else {
echo "Username: " . htmlspecialchars($username);
}
}
7. Database Interaction
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
Selecting Data:
Inserting Data:
$mysqli->close();
Connecting to a Database:
Executing Queries:
8. Error Handling
error_reporting(E_ALL);
ini_set('display_errors', 1);
Try-Catch Block:
try {
// Code that may throw an exception
throw new Exception("An error occurred");
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Program 1
1. Develop the HTML page named as “Myfirstwebpage.html”. 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.)
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>
</body>
</html>
Output
1. <title>: Sets the title of the page that appears on the browser tab.
2. <marquee>: Creates scrolling text (Note: <marquee> is obsolete and not
recommended for modern web practices, but included here as per the requirement).
3. <h1> to <h6>: Represent different levels of headings.
4. <p>: Defines a paragraph.
5. <hr>: Inserts a horizontal line.
6. <br>: Adds a line break.
7. <blockquote>: Used for longer quotations or to indicate a block of quoted text.
8. <pre>: Displays preformatted text, preserving both spaces and line breaks.
9. Logical styles: <b>, <i>, <u>, <sub>, and <sup> are used for bold, italic, underline,
subscript, and superscript text, respectively.
Program 2
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: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
.lab-hour {
background-color: #f4cccc; /* Light red for lab hours */
}
.elective-hour {
background-color: #d9ead3; /* Light green for elective hours */
}
.highlight-row {
background-color: #f9f9f9; /* Light grey for rows */
}
.header {
background-color: #b6d7a8; /* Light green for header */
font-weight: bold;
}
.footer {
background-color: #cfe2f3; /* Light blue for footer */
font-weight: bold;
}
</style>
</head>
<body>
<h1>Class Time Table</h1>
<table>
<!-- Table Header -->
<thead>
<tr class="header">
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
</thead>
<!-- Table Body -->
<tbody>
<tr class="highlight-row">
<td>9:00 - 10:00</td>
<td class="lab-hour">Math</td>
<td class="elective-hour">Art</td>
<td class="lab-hour">Science</td>
<td class="elective-hour">PE</td>
<td class="lab-hour">English</td>
</tr>
<tr class="highlight-row">
<td>10:00 - 11:00</td>
<td class="elective-hour">History</td>
<td class="lab-hour">Math</td>
<td class="elective-hour">Computer Science</td>
<td class="lab-hour">History</td>
<td class="elective-hour">Art</td>
</tr>
<tr class="highlight-row">
<td>11:00 - 12:00</td>
<td class="lab-hour">Science</td>
<td class="elective-hour">English</td>
<td class="lab-hour">Math</td>
<td class="elective-hour">Geography</td>
<td class="lab-hour">Computer Science</td>
</tr>
<tr class="highlight-row">
<td>12:00 - 1:00</td>
<td colspan="5">Lunch Break</td>
</tr>
<tr class="highlight-row">
<td>1:00 - 2:00</td>
<td class="elective-hour">Music</td>
<td class="lab-hour">PE</td>
<td class="elective-hour">Math</td>
<td class="lab-hour">Art</td>
<td class="elective-hour">Science</td>
</tr>
<tr class="highlight-row">
<td>2:00 - 3:00</td>
<td class="lab-hour">Computer Science</td>
<td class="elective-hour">History</td>
<td class="lab-hour">English</td>
<td class="elective-hour">Geography</td>
<td class="lab-hour">Math</td>
</tr>
</tbody>
<!-- Table Footer -->
<tfoot>
<tr class="footer">
<td colspan="6">End of Week Timetable</td>
</tr>
</tfoot>
</table>
</body>
</html>
Output
Program 3
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.
Program
style.css
a:hover {
text-decoration: underline;
color: #1f618d; /* Darker blue on hover */
}
To use these styles in an HTML document, link the style.css file in the <head> section of
your HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Styled Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Heading Level 2</h2>
<h3>Heading Level 3</h3>
<hr>
<p>This is a paragraph. It has a specific font, color, and line-height.</p>
<div>
<p>This is a paragraph inside a div. The div has a background color and border.</p>
<span>This is a span element with different styling.</span>
</div>
<time datetime="2024-08-27">August 27, 2024</time>
<img src="example.jpg" alt="Example Image">
<a href="https://www.example.com">Visit Example.com</a>
</body>
</html>
Output
Program 4
Program
<!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>
<link rel="stylesheet" href="style.css">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
table {
width: 100%;
max-width: 600px;
margin: 0 auto;
border-collapse: collapse;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #3498db;
color: #fff;
font-size: 18px;
}
td {
background-color: #ecf0f1;
}
label {
display: block;
margin-bottom: 5px;
font-size: 16px;
color: #2c3e50;
}
input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
width: 100%;
padding: 8px;
border: 1px solid #bdc3c7;
border-radius: 4px;
font-size: 14px;
}
input[type="submit"] {
background-color: #2ecc71;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #27ae60;
}
.form-container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.form-title {
font-size: 24px;
color: #2c3e50;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="form-container">
<h1 class="form-title">Registration Form</h1>
<form action="#" method="post">
<table>
<tr>
<th colspan="2">Personal Information</th>
</tr>
<tr>
<td><label for="first-name">First Name:</label></td>
<td><input type="text" id="first-name" name="first-name" required></td>
</tr>
<tr>
<td><label for="last-name">Last Name:</label></td>
Output
1. HTML Structure:
o The form is placed inside a div with the class form-container for styling.
o A table is used for layout alignment, with each row containing labels and
corresponding input fields.
o Various input types (text, email, password, select, textarea) are included
to demonstrate different form elements.
2. CSS Styles:
o body: Sets a background color and padding for the entire page.
o table: Centers the table and sets its width. Uses border-collapse to ensure
borders are collapsed into a single line.
o th: Styles table headers with a background color and white text.
o td: Styles table data cells with a light grey background.
o label: Styles labels with font size and color.
o input, select, textarea: Applies styles to form elements including padding,
border, and font size.
o input[type="submit"]: Styles the submit button with a green background,
white text, and hover effect.
o .form-container: Adds padding, background color, border radius, and box
shadow to the form container for a card-like appearance.
o .form-title: Styles the form title with font size and color.
Program 5
Program
<!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;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
header {
background-color: #2c3e50;
color: #ecf0f1;
padding: 20px;
text-align: center;
}
footer {
background-color: #2c3e50;
color: #ecf0f1;
padding: 10px;
text-align: center;
position: fixed;
bottom: 0;
width: 100%;
}
main {
display: flex;
gap: 20px;
margin-bottom: 60px; /* To ensure footer does not overlap content */
}
article {
flex: 2;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
aside {
flex: 1;
background-color: #ecf0f1;
padding: 20px;
border-radius: 8px;
}
section {
margin-bottom: 20px;
}
h1, h2, h3 {
color: #34495e;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #bdc3c7;
}
th {
background-color: #3498db;
color: #fff;
padding: 10px;
}
td {
background-color: #fff;
padding: 10px;
text-align: left;
}
figure {
margin: 0;
padding: 0;
}
figcaption {
font-size: 14px;
color: #7f8c8d;
text-align: center;
}
.figure-container {
background-color: #fff;
padding: 10px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
margin: 20px 0;
}
</style>
</head>
<body>
<header>
<h1>Newspaper Header</h1>
<p>Your source for the latest news</p>
</header>
<main>
<article>
<section>
<h2>Main Article</h2>
<p>This is the main article section. It contains the primary content of the newspaper
page. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<figure class="figure-container">
<img src="example.jpg" alt="Example Image" style="width: 100%; border-radius:
8px;">
<figcaption>Figure 1: Example image caption.</figcaption>
</figure>
<table>
<caption>Sample Table</caption>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td>Data 4</td>
<td>Data 5</td>
<td>Data 6</td>
</tr>
</tbody>
</table>
</section>
</article>
<aside>
<h2>Side Section</h2>
<p>This is an aside section. It contains secondary content or advertisements. Lorem ipsum
dolor sit amet, consectetur adipiscing elit.</p>
</aside>
</main>
<footer>
<p>Newspaper Footer © 2024</p>
</footer>
</body>
</html>
Output
1. HTML Structure:
o <header>: Contains the main heading and subtitle of the newspaper.
o <footer>: Provides footer information, fixed at the bottom of the page.
o <main>: Uses flexbox to layout the article and aside side by side.
o <article>: Represents the main content area of the page.
o <aside>: Contains secondary content or sidebar information.
o <section>: Used within the article to group related content.
o <figure> and <figcaption>: Used to include an image with a caption.
o <table>: Contains tabular data with headers and a caption.
2. CSS Styles:
o body: Sets a background color, font, and padding for the entire page.
o header and footer: Define background colors, text colors, and padding. The
footer is positioned fixed at the bottom of the page.
o main: Utilizes flexbox to create a responsive layout for the main content and
sidebar.
o article and aside: Style the primary content and sidebar with background
colors, padding, and shadows.
o table: Styles the table with borders, background colors for headers, and
padding.
o figure and figcaption: Apply styling to the figure and caption, including
background color and text color.
Program 6
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.
Program
<!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;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
margin: 0;
}
.calculator {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.calculator h1 {
font-size: 24px;
color: #2c3e50;
margin-bottom: 20px;
}
.calculator input,
.calculator select,
.calculator button {
margin-bottom: 10px;
padding: 10px;
border: 1px solid #bdc3c7;
border-radius: 5px;
font-size: 16px;
width: calc(100% - 22px); /* Adjust for padding and border */
}
.calculator button {
background-color: #3498db;
color: #fff;
border: none;
cursor: pointer;
}
.calculator button:hover {
background-color: #2980b9;
}
.calculator .result {
font-size: 18px;
color: #2c3e50;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="calculator">
<h1>Simple Calculator</h1>
<input type="number" id="num1" placeholder="Enter first number">
<input type="number" id="num2" placeholder="Enter second number">
<select id="operation">
<option value="sum">Sum</option>
<option value="difference">Difference</option>
<option value="product">Product</option>
<option value="quotient">Quotient</option>
<option value="remainder">Remainder</option>
<option value="power">Power</option>
<option value="sqrt">Square Root</option>
<option value="square">Square</option>
</select>
<button onclick="calculate()">Calculate</button>
<div class="result" id="result"></div>
</div>
<script>
function calculate() {
// Get values from inputs
const num1 = parseFloat(document.getElementById('num1').value);
const num2 = parseFloat(document.getElementById('num2').value);
const operation = document.getElementById('operation').value;
// Result variable
let result;
break;
case 'product':
result = num1 * num2;
break;
case 'quotient':
result = num1 / num2;
break;
case 'remainder':
result = num1 % num2;
break;
case 'power':
result = Math.pow(num1, num2);
break;
case 'sqrt':
result = Math.sqrt(num1);
break;
case 'square':
result = Math.pow(num1, 2);
break;
default:
result = 'Invalid operation';
}
// Display result
document.getElementById('result').textContent = 'Result: ' + result;
}
</script>
</body>
</html>
Output
Explanation:
1. HTML:
o The HTML structure includes:
Two input fields for numbers.
A <select> dropdown to choose the operation.
A <button> to trigger the calculation.
A <div> to display the result.
2. CSS:
o Styles are applied to center the calculator on the page, style the form elements,
and add hover effects to the button.
o The .calculator class styles the container, adding padding, border-radius,
and box-shadow for a clean look.
3. JavaScript:
o The calculate function retrieves the values from the input fields and the
selected operation from the dropdown.
o It performs the calculation based on the chosen operation using a switch
statement.
o The result is then displayed in the <div> with the id="result".
This simple calculator performs all the specified operations, and the JavaScript handles the
logic for each operation based on user input.
Program 7
Program
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON and CSV Converter</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
margin-bottom: 20px;
}
textarea, input[type="text"], button {
display: block;
width: 100%;
margin-bottom: 10px;
padding: 8px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.result {
white-space: pre-wrap;
background: #f4f4f4;
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Convert JSON to JavaScript Object</h2>
<textarea id="jsonText" placeholder='Enter JSON here'></textarea>
<button onclick="convertJsonToObject()">Convert JSON</button>
<div id="jsonObject" class="result"></div>
</div>
<div class="container">
<h2>Convert JSON to Date</h2>
<input type="text" id="jsonDate" placeholder='Enter JSON Date string'>
<button onclick="convertJsonToDate()">Convert to Date</button>
<div id="dateResult" class="result"></div>
</div>
<div class="container">
<h2>Convert JSON to CSV and CSV to JSON</h2>
<textarea id="jsonCsvText" placeholder='Enter JSON for CSV conversion'></textarea>
<button onclick="convertJsonToCsv()">JSON to CSV</button>
<div id="csvResult" class="result"></div>
<div class="container">
<h2>Create Hash from String</h2>
<input type="text" id="stringInput" placeholder='Enter string to hash'>
<button onclick="createHash()">Create Hash</button>
<div id="hashResult" class="result"></div>
</div>
<script src="app.js"></script>
</body>
</html>
JavaScript (app.js)
Now let's add the JavaScript code to handle each of the tasks.
Output
Explanation:
Program 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.
Program 8a
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.
First, create a PHP file named program_8a.php. This script will handle the counting of
visitors and display the count on the web page.
<?php
// Define the path to the file where the count will be stored
$countFile = 'count.txt';
// HTML output
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visitor Counter</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
margin: 0;
}
.container {
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
}
.count {
font-size: 2em;
color: #007bff;
}
</style>
</head>
<body>
<div class="container">
<h1>Visitor Counter</h1>
<p class="count">You are visitor number: <?php echo $count; ?></p>
</div>
</body>
</html>
Step 2: Explanation
1. File Handling: The PHP script uses count.txt to keep track of the number of
visitors. If this file does not exist, it creates it and initializes the count to 0. Then, it
reads the current count, increments it, and writes the updated count back to the file.
2. HTML/CSS:
o HTML: The page has a simple structure with a heading and a paragraph that displays
the visitor count.
o CSS: Basic styles are applied to center the content and make the page look clean.
The container has a box shadow for a subtle effect, and the visitor count is styled to
stand out.
1. Upload Files: Place program_8a.php on your web server. Ensure that count.txt is
writable by the web server (check permissions if needed).
2. Access Your Page: Open your web browser and navigate to the location where
program_8a.php is hosted. You should see the visitor counter and the count will
increment with each page load.
Output
Program 8b
Develop a PHP program (with HTML/CSS) to sort the student records which are stored in the
database using selection sort.
Steps
1. Set up your database: You'll need a MySQL database with a table for student records.
For simplicity, let's assume you have a database named web_lab_students and a table
named students with fields Stu_name, USN and Sem.
2. Create the PHP script: This script will connect to the database, fetch student records,
sort them using selection sort, and then display the results.
3. Write the HTML/CSS: This part will handle the presentation of the sorted data.
1. Database Setup
Assuming your database web_lab_students and table students are already created, here is
an example of how the table might look:
USE web_lab_students;
<?php
// Database configuration
$host = 'localhost';
$dbname = 'web_lab_students';
$username = 'root'; // Replace with your MySQL username
$password = 'root'; // Replace with your MySQL password
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sorted Student Records</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f4;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 10px;
border: 1px solid #ddd;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
h1 {
color: #333;
}
</style>
</head>
<body>
<h1>Sorted Student Records by Semester</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>USN</th>
<th>Semester</th>
</tr>
</thead>
<tbody>
<?php foreach ($students as $student): ?>
<tr>
<td><?php echo htmlspecialchars($student['Stu_Name']); ?></td>
<td><?php echo htmlspecialchars($student['USN']); ?></td>
<td><?php echo htmlspecialchars($student['Sem']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
Output
Explanation
Make sure your MySQL server is running, and PHP is properly configured.
Place the sort_students.php file in your web server’s root directory.
Access the script via your browser, for example,
http://localhost/sort_students.php.
This script will display student records sorted by the sem field using the selection sort
algorithm. Adjust database credentials and table schema as needed.
Program 9
Program
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Animations and Manipulations</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f4;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
p, ul {
margin: 10px 0;
}
.animated-div {
width: 100px;
height: 100px;
background-color: #3498db;
margin-top: 20px;
transition: background-color 0.5s;
}
</style>
</head>
<body>
<div class="container">
<h1>jQuery Example</h1>
<li>Item 1</li>
<li>Item 2</li>
</ul>
$('#appendListItem').click(function() {
$('#list').append('<li>New Item</li>');
});
// Animate div
$('#animateDiv').click(function() {
$(‘#animatedDiv’).animate({
width: '200px',
height: '200px'
}, 1000, function() {
// Change color after animation completes
$(this).css('background-color', '#e74c3c');
});
});
});
</script>
</body>
</html>
Output
Explanation:
1. HTML:
o Contains a paragraph and a list to which content can be appended.
o Includes buttons for appending text, appending list items, and animating a div.
o The div with the id="animatedDiv" is styled and animated.
2. CSS:
o Basic styling for the body, container, paragraph, and list.
o The .animated-div class provides initial styling and a transition effect for
background color changes.
3. jQuery:
o Append Content:
$('#appendText').click(): Appends text to the existing paragraph
when the button is clicked.
$('#appendListItem').click(): Appends a new list item to the
existing list when the button is clicked.
o Animate Div:
$('#animateDiv').click(): Animates the size of the div when the
button is clicked. After the animation completes, the background color
of the div changes to red.
This script demonstrates basic jQuery functionalities for manipulating and animating HTML
elements. You can save the above code into an index.html file and open it in a web browser
to see it in action.
Program 10
Program
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AJAX with and without jQuery</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f4;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
button {
margin: 10px;
padding: 10px;
border: 1px solid #bdc3c7;
border-radius: 5px;
background-color: #3498db;
color: #fff;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
pre {
background-color: #ecf0f1;
padding: 10px;
border-radius: 5px;
white-space: pre-wrap;
}
</style>
</head>
<body>
<div class="container">
<h1>AJAX Examples</h1>
<h2>JSON Data</h2>
<pre id="jsonOutput"></pre>
</div>
Output
Explanation:
1. HTML:
o The HTML structure includes buttons for different AJAX operations and
output areas to display results.
o There are buttons for loading text and JSON data using both vanilla JavaScript
and jQuery, as well as for parsing JSON.
2. CSS:
o Basic styling is applied to the body, buttons, and output areas to make the page
visually appealing.
3. JavaScript:
o Without jQuery:
The loadTextWithoutJQuery button uses vanilla JavaScript's
XMLHttpRequest to load and display text from a file (sample.txt).
o With jQuery:
The loadTextWithJQuery button uses jQuery's $.ajax() method to
load and display text from a file.
The loadJson button uses jQuery's $.getJSON() method to fetch and
display JSON data from data.json.
The parseJson button demonstrates $.parseJSON() by parsing a
JSON string and displaying its contents.
Files Needed:
You can save the provided HTML code into an index.html file and ensure that sample.txt
and data.json are in the same directory as your HTML file. Open index.html in a web
browser to see the examples in action.
Remember that AJAX requests need to be served from a web server or local server
environment to work correctly (i.e., they might not work if just opened directly from the file
system due to browser security restrictions). You can use tools like Live Server in VS Code
or a simple local server like http-server in Node.js for testing.
VIVA QUESTIONS
HTML
1. What is HTML, and what does it stand for?
o HTML stands for HyperText Markup Language. It is used to structure content
on the web.
11. What is the purpose of the alt attribute in the <img> tag?
o The alt attribute provides alternative text for the image if it cannot be
displayed. It also improves accessibility.
31. What is the difference between the <strong> and <b> tags?
o The <strong> tag indicates that text is of strong importance, while <b> simply
applies bold styling without implying importance.
Stylesheets – CSS
5. How does the id selector differ from the class selector in CSS?
o The id selector targets a single unique element with a specific id attribute,
while the class selector can target multiple elements with the same class. The
id selector is defined with a hash symbol (e.g., #my-id), and the class selector
is defined with a dot (e.g., .my-class).
14. What is the display property in CSS, and what are its common values?
o The display property specifies how an element is displayed on the page.
Common values include block, inline, inline-block, none, and flex.
19. What is the position property in CSS, and what are its values?
o The position property specifies how an element is positioned in the document.
Common values include static, relative, absolute, fixed, and sticky.
22. How do you change the font size of an element using CSS?
o Use the font-size property. Example: font-size: 16px;.
27. How do you set the width of an element to 100% of its parent container?
o Use width: 100%; in the CSS rule for the element.
30. How do you remove the default underline from links using CSS?
o Use the text-decoration property with the value none. Example: a { text-
decoration: none; }.
32. How do you change the font family of an element using CSS?
o Use the font-family property. Example: font-family: Arial, sans-serif;.
a:hover {
color: red;
}
36. How do you apply different styles to even and odd table rows?
o Use the :nth-child pseudo-class with the even or odd keyword. Example:
tr:nth-child(even) {
background-color: #f2f2f2;
}
37. What is the visibility property in CSS, and how does it differ from display?
o The visibility property controls whether an element is visible or not, with
values visible and hidden. Unlike display: none, visibility: hidden keeps the
element in the layout but hides it
PHP
1. What is PHP?
o PHP (Hypertext Preprocessor) is a widely-used, open-source server-side
scripting language designed primarily for web development. It can be
embedded into HTML and interacts with databases to generate dynamic
content.
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
// Process each row
}
}
11. What is SQL injection and how can you prevent it?
o SQL injection is a security vulnerability where an attacker can manipulate
SQL queries by injecting malicious input. To prevent it, use prepared
statements and parameterized queries:
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
JavaScript
11. What are JavaScript modules and why are they used?
o JavaScript modules are a way to organize code by exporting and importing
functions, objects, or primitives from one file to another. This improves code
maintainability and encapsulation. Modules are typically managed using the
import and export keywords.
AJAX
4. What are the key methods and properties of the XMLHttpRequest object?
o Key methods include open(), send(), setRequestHeader(), and abort().
Key properties include readyState, status, and responseText or
responseXML.
10. How does AJAX differ from traditional full-page form submission?
o Traditional form submission involves sending the entire form data to the
server and refreshing the page with the server's response. AJAX allows for
sending and receiving data asynchronously without reloading the page, which
enables partial updates and a more seamless user experience.
JQUERY
typical inclusion in HTML is done with a <script> tag, either referencing the
jQuery library from a CDN or from a local file:
<script src="https://code.jquery.com/jquery-3.6.0.min.js">
</script>
or
<script src="path/to/your/local/jquery.min.js"></script>
For example:
$('#myElement').parent(); // Selects the parent element
$('#myElement').find('.child'); // Selects child elements with
class 'child'