Web Programming Lab DA2
Web Programming Lab DA2
Digital Assessment-2
Slot: L15+L16/L29+L30
Exercise 11
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Income Values</title>
</head>
<body>
<h2>Income Values</h2>
<div id="incomeTable"></div>
<script>
// Define the array of income values
var incomes = [30000, 45000, 60000, 55000, 70000];
</body>
</html>
Output
2. Get income values of a family members and
display the total income using a popup window.
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function calculateTotal() {
</script>
</head>
<body>
<form>
</form>
</body>
</html>
Output
With input values and final result
3. Update two income values due to yearly hike and
show the updated total income in a paragraph element
along with other member details.
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Family Income Details</title>
<script>
function calculateTotal() {
// Get values from input fields
var name1 = document.getElementById("name1").value;
var initialIncome1 = parseFloat(document.getElementById("income1").value);
var hike1 = parseFloat(document.getElementById("hike1").value);
<form>
<label for="name1">Name of Family Member 1:</label><br>
<input type="text" id="name1" name="name1" value=""><br><br>
<p id="details"></p>
</body>
</html>
Output
With input values and final result
4. Arrange the income values in ascending and
descending order.
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function calculateTotal() {
</script>
</head>
<body>
<form>
</form>
<p id="details"></p>
</body>
</html>
Output
5. Create a higher income array by checking
the condition >50000
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Higher Income Array</title>
<script>
function createHigherIncomeArray() {
// Get income values from input fields
var income1 = parseFloat(document.getElementById("income1").value);
var income2 = parseFloat(document.getElementById("income2").value);
var income3 = parseFloat(document.getElementById("income3").value);
var income4 = parseFloat(document.getElementById("income4").value);
<form>
<label for="income1">Income of Family Member 1:</label><br>
<input type="number" id="income1" name="income1" value=""><br><br>
<p id="higherIncome"></p>
</body>
</html>
Output
6. Create a numeric indexed string valued array
using fruit names and display the fruits array
in html page as ordered list.
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fruits List</title>
</head>
<body>
<h2>Fruits List</h2>
<script>
function generateOrderedList(array) {
listHTML += "</ol>";
return listHTML;
fruitsListElement.innerHTML = generateOrderedList(fruits);
document.body.appendChild(fruitsListElement);
</script>
</body>
</html>
Output
7. Write a JavaScript that calculates the
squares and cubes of the numbers from 0 to
10 and outputs html text that displays the
resulting values in an html table format.
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Squares and Cubes</title>
</head>
<body>
<div id="outputTable"></div>
<script>
// Function to calculate squares and cubes and generate HTML table
function generateTable() {
var tableHTML = "<table
border='1'><tr><th>Number</th><th>Square</th><th>Cube</th></tr>";
tableHTML += "</table>";
return tableHTML;
}
</body>
</html>
Output
8. Design a volunteer registration form for ABC
food bank website using HTML, CSS and apply
validation.
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Volunteer Registration Form</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="container">
<form id="volunteerForm" action="#" method="post">
<h2>Volunteer Registration Form</h2>
<div class="form-group">
<label for="fullname">Full Name:</label>
<input type="text" id="fullname" name="fullname" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{10}" required>
<small>Format: 1234567890</small>
</div>
<div class="form-group">
<label for="message">Message (Optional):</label>
<textarea id="message" name="message" rows="4"></textarea>
</div>
<button type="submit">Submit</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
Output
Exercise 12
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Dynamic Interactions</title>
<style>
#areaA, #areaB, #areaC, #areaD {
width: 200px;
height: 100px;
margin-bottom: 10px;
text-align: center;
line-height: 100px;
cursor: pointer;
}
</style>
</head>
<body>
function cycleBackgroundColor(areaId) {
var area = document.getElementById(areaId);
var colors = ["blue", "lime", "red", "yellow", "green"];
var currentIndex = colors.indexOf(area.style.backgroundColor);
var nextIndex = (currentIndex + 1) % colors.length;
area.style.backgroundColor = colors[nextIndex];
}
function changeToRed(areaId) {
var area = document.getElementById(areaId);
area.style.backgroundColor = 'red';
}
function changeToGreen(areaId) {
var area = document.getElementById(areaId);
area.style.backgroundColor = 'green';
}
function changeToPink(areaId) {
var area = document.getElementById(areaId);
area.style.backgroundColor = 'pink';
}
</script>
</body>
</html>
Output
2. Create a simple calculator using html, css and
javascript that will do the arithmetic operations
using mouse clicks and appropriate event handlers.
# Code
<!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>
.calculator {
width: 250px;
margin: 50px auto;
padding: 10px;
border: 2px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
button {
width: 50px;
height: 50px;
margin: 5px;
font-size: 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" id="display" readonly>
<br>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('+')">+</button>
<br>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="appendToDisplay('-')">-</button>
<br>
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('*')">*</button>
<br>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="appendToDisplay('.')">.</button>
<button onclick="clearDisplay()">C</button>
<button onclick="calculate()">=</button>
<br>
</div>
<script>
function appendToDisplay(value) {
document.getElementById("display").value += value;
}
function clearDisplay() {
document.getElementById("display").value = "";
}
function calculate() {
var expression = document.getElementById("display").value;
var result = eval(expression);
document.getElementById("display").value = result;
}
</script>
</body>
</html>
Output
Exercise 13
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
font-family: Arial, sans-serif;
.container {
max-width: 600px;
padding: 20px;
border-radius: 5px;
h2 {
text-align: center;
label {
display: block;
margin-bottom: 5px;
width: 100%;
padding: 8px;
margin-bottom: 10px;
border-radius: 5px;
box-sizing: border-box;
}
button {
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
table, th, td {
padding: 10px;
text-align: left;
th {
background-color: #f2f2f2;
.update-button {
background-color: #28a745;
.error {
color: red;
</style>
</head>
<body>
<div class="container">
<form id="jobApplicationForm">
<label for="email">Email:</label>
<label for="phone">Phone:</label>
<label for="resume">Resume:</label>
<button type="submit">Submit</button>
</form>
<table>
<tr><th>Field</th><th>Value</th></tr>
<tr><td>Email</td><td id="applicantEmail"></td></tr>
<tr><td>Phone</td><td id="applicantPhone"></td></tr>
<tr><td>Resume</td><td id="applicantResume"></td></tr>
</table>
</div>
</div>
<script>
function submitForm(event) {
event.preventDefault();
document.getElementById("applicantFullName").textContent = fullName;
document.getElementById("applicantEmail").textContent = email;
document.getElementById("applicantPhone").textContent = phone;
document.getElementById("applicantResume").textContent = resume;
document.getElementById("jobApplicationForm").reset();
document.getElementById("applicantDetails").style.display = "block";
function showFormForUpdate() {
document.getElementById("applicantDetails").style.display = "none";
document.getElementById("jobApplicationForm").reset();
document.getElementById("jobApplicationForm").addEventListener("submit",
submitForm);
</script>
</body>
</html>
Output
Exercise 14
# Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Train Reservation Form</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="container">
<h2>Train Reservation Form</h2>
<form id="reservationForm" onsubmit="submitForm(event)">
<label for="fullName">Full Name:</label>
<input type="text" id="fullName" name="fullName" required>
<label for="age">Age:</label>
<input type="number" id="age" name="age" required>
<label for="berth">Berth Selection:</label>
<select id="berth" name="berth" required>
<option value="lower">Lower</option>
<option value="middle">Middle</option>
<option value="upper">Upper</option>
</select>
<button type="submit">Submit</button>
<button type="button" onclick="resetForm()">Reset</button>
</form>
<div id="reservationDetails" style="display: none;">
<h2>Reservation Details</h2>
<table id="detailsTable">
<tr><th>Field</th><th>Value</th></tr>
</table>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Output