Web Lab Study Material
Web Lab Study Material
Program 2
<!DOCTYPE html>
<html>
<head>
<title>Time Table</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
text-align: center;
}
th, td {
border: 1px solid black;
padding: 15px;
}
th {
background-color: green;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.lab {
background-color: #ffcccb;
}
.elective {
background-color: #ccffcc;
}
.row-span {
background-color: #ffcc99;
}
.col-span {
background-color: #ffff99;
}
tfoot {
font-weight: bold;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Class Time Table</h1>
<table>
<thead>
<tr>
<th colspan="6">Class Schedule</th>
</tr>
<tr>
<th>Day</th>
<th>9:00 - 10:00</th>
<th>10:00 - 11:00</th>
<th>11:00 - 12:00</th>
<th>12:00 - 1:00</th>
<th>1:00 - 2:00</th>
</tr>
</thead>
<tbody>
<tr>
<td>Monday</td>
<td>Math</td>
<td class="lab" colspan="2">Physics Lab</td>
<td>Lunch</td>
<td>Electronics</td>
</tr>
<tr>
<td>Tuesday</td>
<td class="elective">History</td>
<td>Math</td>
<td>Physics</td>
<td class="lab">Chemistry Lab</td>
<td>Lunch</td>
</tr>
<tr>
<td>Wednesday</td>
<td>Computer Science</td>
<td>Math</td>
<td class="elective">Music</td>
<td rowspan="2" class="row-span">Project Work</td>
<td>Lunch</td>
</tr>
<tr>
<td>Thursday</td>
<td>Math</td>
<td>Physics</td>
<td class="lab">Computer Lab</td>
<td>Electronics</td>
</tr>
<tr>
<td>Friday</td>
<td class="col-span" colspan="2">Seminar</td>
<td>Physics</td>
<td>Lunch</td>
<td>Math</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="6">Note: Labs and Electives are highlighted with different colors.</td>
</tr>
</tfoot>
</table>
</body>
</html>
Program 3
<!DOCTYPE html>
<html lang="en">
<head>
<title>Styled HTML Elements</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>This is an H2 Heading</h2>
<h3>This is an H3 Heading</h3>
<hr>
<p>This is a regular paragraph.</p>
<p class="special-paragraph">This is a special paragraph styled using a class selector.</p>
<div id="unique-div">
This is a unique div styled with an ID selector.
<span>This span is inside a div and styled with a descendant selector.</span>
</div>
<time datetime="2024-09-13">September 13, 2024</time> -
color: #4CAF50;
text-align: center;
}
/* Style for h3 tag */
h3 {
color: #ff5722;
text-align: center;
}
/* Style for hr tag */
hr {
border: 2px solid #333;
width: 80%;
}
/* Style for p tag */
p{
font-size: 16px;
color: green;
}
/* Style for span tag */
span {
font-weight: bold;
}
/* Style for time tag */
time {
font-style: italic;
color: purple;
}
/* Style for img tag */
img {
width: 3x0%; }
/* Style for a tag */
a{
color: blue;
}
/* Class selector for a special paragraph */
.special-paragraph {
font-style: italic;
border-left: 4px solid;
padding-left: 10px;
}
/* ID selector for unique div */
#unique-div {
background-color: #ffeb3b;
font-size: 18px;
color: blue;
}
Program 4
<!DOCTYPE html>
<html lang="en">
<head>
<title>Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: pink;
}
h2 {
text-align: center;
}
.form-container {
background: white;
width: 60%;
}
td {
padding: 10px;
vertical-align: top;
}
width: auto;
}
input[type="submit"] {
background: green;
color: #fff;
padding: 10px;
}
.note {
color: red;
text-align: center;
}
</style>
</head>
<body>
<h2>Registration Form</h2>
<div class="form-container">
<form action="#" method="post">
<table>
<tr>
<td><label for="name">Name:</label></td>
</tr>
<tr>
<td><label for="dob">Date of Birth:</label></td>
<td><input type="date" id="dob" name="dob" required></td>
</tr>
<tr>
<td><label for="phone">Phone Number:</label></td>
<td><input type="tel" id="phone" name="phone" pattern="[0-9]{10}"
required></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio" id="male" name="gender" value="male" required>
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female" required>
<label for="female">Female</label>
</td>
</tr>
<tr>
<td><label for="course">Select Course:</label></td>
<td>
<td>Hobbies:</td>
<td>
<input type="checkbox" id="sports" name="hobbies" value="sports">
<label for="sports">Sports</label>
<input type="checkbox" id="music" name="hobbies" value="music">
<label for="music">Music</label>
<input type="checkbox" id="reading" name="hobbies" value="reading">
<label for="reading">Reading</label>
</td>
</tr>
<tr>
<td><label for="address">Address:</label></td>
<td><textarea id="address" name="address" rows="4"
required></textarea></td>
</tr>
<tr>
<td colspan="2" class="note">* All fields are mandatory</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</div>
</body> </html>
Program 5
<!DOCTYPE html>
<html lang="en">
<head>
<title>Online Newspaper</title>
<style>
body {
font-family: Arial;
margin: 0;
}
header {
background-color: #4CAF50;
color: white;
padding: 20px;
text-align: center;
}
footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
position: fixed;
width: 100%;
bottom: 0;
}
section {
padding: 20px;
margin: 20px;
}
aside {
background-color: #f0f0f0;
padding: 15px;
width: 30%;
float: right;
margin: 20px;
}
article {
background-color: #eef5f9;
padding: 15px;
margin-bottom: 20px;
border-radius: 8px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<header>
<th>Field</th>
<th>Key Development</th>
<th>Impact</th>
</tr>
</thead>
<tbody>
<tr>
<td>Healthcare</td>
<td>AI-assisted Surgeries</td>
<td>Improved accuracy and efficiency</td>
</tr>
<tr>
<td>Transportation</td>
<td>Autonomous Vehicles</td>
<td>Reduced traffic accidents</td>
</tr>
<tr>
<td>Retail</td>
<td>AI Chatbots</td>
<td>Enhanced customer service</td>
</tr>
</tbody>
</table>
</article>
</section>
<aside>
<h3>Latest Headlines</h3>
<ul>
</aside>
<footer>
<p>© 2024 Daily News Online. All rights reserved.</p>
</footer>
</body>
</html>
Program 6
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple Calculator</title>
<style>
body {
font-family: Arial;
background: grey;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
}
.calculator {
background: #fff;
padding: 20px;
text-align: center;
}
h2 {
color: #4CAF50;
margin-bottom: 20px;
}
input, button {
margin: 10px 5px;
padding: 10px;
cursor: pointer;
}
#result {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<div class="calculator">
<h2>Simple Calculator</h2>
<input type="number" id="num1" placeholder="First Number">
<input type="number" id="num2" placeholder="Second Number">
<div>
<button onclick="calculate('sum')">Sum</button>
<button onclick="calculate('diff')">Difference</button>
<button onclick="calculate('prod')">Product</button>
<button onclick="calculate('quot')">Quotient</button>
<button onclick="calculate('mod')">Remainder</button>
<button onclick="calculate('power')">Power</button>
<button onclick="calculate('square')">Square</button>
<button onclick="calculate('sqrt')">Square Root</button>
</div>
<div id="result">Result: 0</div>
</div>
<script>
function calculate(op) {
const num1 = parseFloat(document.getElementById('num1').value) || 0;
const num2 = parseFloat(document.getElementById('num2').value) || 0;
let result;
switch (op) {
case 'sum': result = num1 + num2; break;
case 'diff': result = num1 - num2; break;
case 'prod': result = num1 * num2; break;
</body>
</html>
Program 7
<!DOCTYPE html>
<html lang="en">
<head>
<title>JSON Operations</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 10px;
}
h2 {
color: #333;
}
textarea, input, button, pre {
display: block;
margin: 10px 0;
width: 100%;
}
textarea {
height: 100px;
}
button {
padding: 8px;
background: #4CAF50;
color: white;
border: none;
cursor: pointer;
} }
</style>
</head>
<body>
<h2>JSON Operations</h2>
<!-- JSON to Object -->
<label for="jsonInput">Enter JSON Text:</label>
<textarea id="jsonInput" placeholder='{"name": "Alice", "age": 25, "date": "2024-09-
13"}'></textarea>
<button onclick="convertJsonToObject()">Convert JSON to Object</button>
<pre id="jsonObjectOutput">JavaScript Object will appear here...</pre>
return JSON.parse(input);
} catch {
return null;
}
};
function convertJsonToObject() {
const json = safeParseJSON(document.getElementById('jsonInput').value);
updateOutput('jsonObjectOutput', json ? JSON.stringify(json, null, 2) : 'Invalid JSON
format.');
}
function convertJsonToDate() {
const json = safeParseJSON(document.getElementById('jsonInput').value);
}
}
function convertJsonToCsv() {
const json = safeParseJSON(document.getElementById('jsonInput').value);
if (json) {
const keys = Object.keys(json);
const values = Object.values(json);
updateOutput('csvOutput', `${keys.join(',')}\n${values.join(',')}`);
} else {
updateOutput('csvOutput', 'Invalid JSON format.');
}
}
function convertCsvToJson() {
const csv = document.getElementById('csvInput').value;
try {
const [header, data] = csv.split('\n');
}, {});
updateOutput('jsonFromCsvOutput', JSON.stringify(json, null, 2));
} catch {
updateOutput('jsonFromCsvOutput', 'Invalid CSV format.');
}
function createHash() {
const str = document.getElementById('hashStringInput').value;
let hash = 0;
8a)
<?php
// Define the file path to store the visitor count
$filename = 'count.txt';
file_put_contents($filename, '0');
}
file_put_contents($filename, $count);
<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;
text-align: center;
background-color: #f4f4f4;
margin: 0;
padding: 50px;
}
h1 {
color: #333;
}
.container {-
background: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: inline-block;
padding: 20px;
}
p{
font-size: 1.2em;
color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Visitor Counter</h1>
<p>Number of visitors to this page: <?php echo $count; ?></p>
</div>
</body>
</html>
8b)
CREATE DATABASE school;
USE school;
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
grade INT
);
INSERT INTO students (name, grade) VALUES
('Alice', 85),
('Bob', 70),
('Charlie', 95),
('Diana', 88);
<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "school";
$result = $conn->query($sql);
$students = array();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$students[] = $row;
}
}
// Selection Sort function
function selectionSort(&$arr) {
$n = count($arr);
}
}
// Swap the minimum element with the first element
if ($minIndex != $i) {
$temp = $arr[$i];
$arr[$i] = $arr[$minIndex];
$arr[$minIndex] = $temp;
}
}
}
// Sort students by grade
selectionSort($students);
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sorted Student Records</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
background-color: #f4f4f4;
}
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Sorted Student Records</h1>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
<?php foreach ($students as $student): ?>
<tr>
<td><?php echo htmlspecialchars($student['id']); ?></td>
<td><?php echo htmlspecialchars($student['name']); ?></td>
<td><?php echo htmlspecialchars($student['grade']); ?></td>
</tr>